-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
43 lines (28 loc) · 1.14 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 generatePassword = () => {
const passwordLength = document.getElementById("password-length").value || 12;
const symbols = "!@#$%^&*(){}[]=<>/,.";
const numbers = "1234567890";
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const isIncludeSymbol = document.getElementById("include-symbols").checked;
const isIncludeNumber = document.getElementById("include-numbers").checked;
const isIncludeLowercase =
document.getElementById("include-lowercase").checked;
const isIncludeUppercase =
document.getElementById("include-uppercase").checked;
let charSet = "";
if (isIncludeSymbol) charSet += symbols;
if (isIncludeNumber) charSet += numbers;
if (isIncludeLowercase) charSet += lowercase;
if (isIncludeUppercase) charSet += uppercase;
let password = "";
if (charSet === "") {
alert("Please select at least one option");
return;
}
for (let i = 0; i < passwordLength; i++) {
const randomIndex = Math.floor(Math.random() * charSet.length);
password += charSet[randomIndex];
}
document.getElementById("generated-password").innerHTML = password;
};