-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (34 loc) · 1.17 KB
/
script.js
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
39
40
41
42
43
const lengthEl = document.getElementById("length");
const uppercaseEl = document.getElementById("uppercase");
const lowercaseEl = document.getElementById("lowercase");
const numbersEl = document.getElementById("numbers");
const symbolsEl = document.getElementById("symbols");
const generateEl = document.getElementById("generate");
const passwordEl = document.getElementById("password");
const uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const symbols = "!@#$%^&*()_+={}[]\\|;:'\",.<>?";
function generatePassword() {
const length = lengthEl.value;
let password = "";
let charset = "";
if (uppercaseEl.checked) {
charset += uppercaseLetters;
}
if (lowercaseEl.checked) {
charset += lowercaseLetters;
}
if (numbersEl.checked) {
charset += numbers;
}
if (symbolsEl.checked) {
charset += symbols;
}
for (let i = 0; i < length; i++) {
password += charset.charAt(Math.floor(Math.random() * charset.length));
}
passwordEl.innerText = password;
passwordEl.parentElement.style.display = "block";
}
generateEl.addEventListener("click", generatePassword);