-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (51 loc) · 1.77 KB
/
script.js
File metadata and controls
62 lines (51 loc) · 1.77 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
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 genBtn= document.getElementById("genBtn");
let symbols= document.getElementById("symbols");
let copyIcon= document.getElementById('copyicon')
//showing input slider value
sliderValue.textContent = inputSlider.value;
//when we click (basically when we give input)
inputSlider.addEventListener('input',()=>{
sliderValue.textContent = inputSlider.value;
})
genBtn.addEventListener('click',()=>{
passBox.value= generatePassword();
})
let upperChars= "ABCDEFGHIJKLMNIOPQRSTUVWXYZ";
let lowerChars= "abcdefghijklmnopqrstuvwxyz";
let allnumbers="0123456789";
let allsymbols="*&^%$#@!~"
//function to generate password
function generatePassword(){
let genPassword = '';
let allChars="";
allChars+=lowercase.checked? lowerChars: "";
allChars+=uppercase.checked? upperChars: "";
allChars+=numbers.checked? allnumbers: "";
allChars+=allsymbols.checked? symbols: "";
if(allChars=="" || allChars.length==0){
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!='' || passBox.value>=1){
navigator.clipboard.writeText(passBox.value);
copyIcon.innerText='Copied';
copyIcon.title="password copied";
}
setTimeout(()=>{
copyIcon.innerHTML="content_copy";
copyIcon.title="";
},3000);
});