-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (20 loc) · 879 Bytes
/
script.js
File metadata and controls
24 lines (20 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
document.getElementById("generate-btn").onclick = function() {
let length = parseInt(document.getElementById("num-input").value);
if (!length || length <= 0) {
alert("Please enter a valid number.");
return;
}
document.getElementById("pw1").textContent = generatePassword(length);
document.getElementById("pw2").textContent = generatePassword(length);
document.getElementById("pw3").textContent = generatePassword(length);
document.getElementById("pw4").textContent = generatePassword(length);
};
function generatePassword(length) {
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]}\|";
let password = "";
for (let i = 0; i < length; i++) {
let randIndex = Math.floor(Math.random() * chars.length);
password += chars[randIndex];
}
return password;
}