-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (45 loc) · 1.57 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
44
45
46
47
48
49
50
51
52
// Set Variables
let abc = "abcdefghijklmnopqrstuvwxyz";
let abcUpper = abc.toUpperCase();
let num = "0123456789";
let symbols = "!@#$%^&*()_+-=<>?{}";
let userPass = "";
let passGrp = "";
// Prompt to start Password Generation
window.onload = alert("Please click 'Generate password' to create a random password.");
// Start Password Generation
document.getElementById("generate").addEventListener("click", generatePassword);
function generatePassword() {
// Set Password length
let passLength = prompt("Please enter your password length between 8 and 128 numbers.");
if (passLength < 8 || passLength > 128) {
alert("Your password length must be between 8 and 128 numbers!\nPlease start over.");
} else {
// Set Password options
let selectAbc = confirm("Would you like to use lower case letters?");
let selectAbcUpper = confirm("Would you like to use upper case letters?");
let selectNum = confirm("Would you like to use numbers?");
let selectSymbols = confirm("Would you like to use symbols?");
//Generate password
if (selectAbc) {
passGrp += abc;
}
if (selectAbcUpper) {
passGrp += abcUpper;
}
if (selectNum) {
passGrp += num;
}
if (selectSymbols) {
passGrp += symbols;
}
if (passGrp.length == 0) {
alert("You must select a password option.\nPlease start over.");
}
for (let i = 0; i < passLength; i++) {
userPass += passGrp.charAt(Math.floor(Math.random() * passGrp.length));
}
// Put password on page
document.getElementById("password").innerHTML = userPass;
}
}