-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 886 Bytes
/
script.js
File metadata and controls
28 lines (24 loc) · 886 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
25
26
27
28
// --- Element Selection ---
const generateBtn = document.getElementById("pasw-btn");
const passwordBoxes = document.querySelectorAll(".box");
function generateSecurePassword(length) {
const allChars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()";
// Create a new array to hold secure random numbers
const randomValues = new Uint32Array(length);
window.crypto.getRandomValues(randomValues);
let password = "";
for (let i = 0; i < length; i++) {
// Use the secure random number to pick a character from our list
password += allChars[randomValues[i] % allChars.length];
}
return password;
}
// --- Event Listener ---
generateBtn.addEventListener("click", () => {
passwordBoxes.forEach((box) => {
const newPassword = generateSecurePassword(15);
box.textContent = newPassword;
box.style.height = "2rem";
});
});