-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (52 loc) · 1.84 KB
/
script.js
File metadata and controls
70 lines (52 loc) · 1.84 KB
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 inputSlider = document.getElementById("inputSlider");
let sliderValue = document.getElementById("sliderValue");
let passBox = document.getElementById("passBox");
let lowercase = document.getElementById("lowercase");
let uppercase = document.getElementById("uppercase");
let numbers = document.getElementById("numbers");
let symbols = document.getElementById("symbols");
let genBtn = document.getElementById("genBtn");
let copyIcon = document.getElementById("copyIcon");
sliderValue.textContent = inputSlider.value;
inputSlider.addEventListener("input",function(){
sliderValue.textContent = inputSlider.value;
});
genBtn.addEventListener("click", ()=>{
passBox.value = generatePassword();
});
let lowerChars ="abcdefghijklmnopqrstuvwxyz";
let upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let allNumbers = "0123456789";
let allSymbols = "~!@#$%^&*"
function generatePassword(){
let genPassword = "";
let allChars = "";
allChars += lowercase.checked ? lowerChars : "";
allChars += uppercase.checked ? upperChars : "";
allChars += symbols.checked ? allSymbols : "";
allChars += numbers.checked ? allNumbers : "";
if(allChars == "" || allChars.length == 0){
alert("Select atleast one option");
return genPassword;
}
let i = 1;
while( i <= inputSlider.value ){
genPassword += allChars.charAt(Math.floor(Math.random() * allChars.length));
i++;
}
return genPassword;
}
copyIcon.addEventListener("click", ()=>{
if(passBox.value == ""){
alert("Generate a valid password");
}
else{
navigator.clipboard.writeText(passBox.value);
copyIcon.innerHTML = "check_circle";
copyIcon.title = "Password Copied";
setTimeout(() => {
copyIcon.innerHTML ="content_copy";
copyIcon.title ="";
}, 3000);
}
});