-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (59 loc) · 1.92 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let form = document.getElementById("myForm");
function handleForm(event) {
event.preventDefault();
}
form.addEventListener("submit", handleForm);
let genPass = document.getElementById("genPass");
let generate = () => {
var passLen = document.getElementById("passLength");
var uppercaseCheck = document.getElementById("uppercaseCheck");
var lowercaseCheck = document.getElementById("lowercaseCheck");
var numbersCheck = document.getElementById("numbersCheck");
var symbolsCheck = document.getElementById("symbolsCheck");
genPass.value = generatePass(
passLen.value,
uppercaseCheck.checked,
lowercaseCheck.checked,
numbersCheck.checked,
symbolsCheck.checked
);
};
function passwordLength(len) {
document.getElementById("passLengthLabel").innerHTML =
"Password Length: " + len;
}
function generatePass(len, upper, lower, num, sym) {
var temp = "";
for (let i = 0; i < len; i++) {
let rand = Math.floor(Math.random() * 4);
if (rand == 0 && upper) {
temp = temp.concat(getRandomUpper());
} else if (rand == 1 && lower) {
temp = temp.concat(getRandomLower());
} else if (rand == 2 && num) {
temp = temp.concat(getRandomNumber());
} else if (rand == 3 && sym) {
temp = temp.concat(getRandomSymbol());
} else {
i--;
} //if we get random but other is not true then un-interate
}
return temp;
}
function getRandomUpper() {
return String.fromCharCode(65 + Math.floor(Math.random() * 26));
}
function getRandomLower() {
return String.fromCharCode(97 + Math.floor(Math.random() * 26));
}
function getRandomSymbol() {
return String.fromCharCode(33 + Math.floor(Math.random() * 15));
}
function getRandomNumber() {
return Math.floor(Math.random() * 10);
}
function copyPassword() {
genPass.select();
// document.execCommand("copy");
navigator.clipboard.writeText(genPass.value);
}