-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (31 loc) · 1.3 KB
/
script.js
File metadata and controls
38 lines (31 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const display = document.getElementById('password-display');
const lengthSlider = document.getElementById('length-slider');
const lengthNum = document.getElementById('length-num');
const genBtn = document.getElementById('generate-btn');
const copyBtn = document.getElementById('copy-btn');
const alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbers = "0123456789";
const symbols = "!@#$%^&*()_+~`|}{[]:;?><,./-=";
// Update length display
lengthSlider.oninput = () => lengthNum.textContent = lengthSlider.value;
function generatePassword() {
let charPool = alpha;
if (document.getElementById('inc-numbers').checked) charPool += numbers;
if (document.getElementById('inc-symbols').checked) charPool += symbols;
let password = "";
for (let i = 0; i < lengthSlider.value; i++) {
const randomIndex = Math.floor(Math.random() * charPool.length);
password += charPool[randomIndex];
}
display.value = password;
}
// Copy to Clipboard Logic
copyBtn.onclick = () => {
if (!display.value) return;
navigator.clipboard.writeText(display.value);
// Quick Visual Feedback
const originalIcon = copyBtn.textContent;
copyBtn.textContent = "✅";
setTimeout(() => copyBtn.textContent = originalIcon, 1500);
};
genBtn.onclick = generatePassword;