-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (37 loc) · 1.3 KB
/
script.js
File metadata and controls
44 lines (37 loc) · 1.3 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
const inputSlider=document.getElementById('inputSlider');
const sliderValue=document.getElementById('sliderValue');
const Span=sliderValue.querySelector("span");
const passBox=document.getElementById("passBox");
const lowercase=document.getElementById("lowercase");
const uppercase=document.getElementById("uppercase");
const numbers=document.getElementById("numbers");
const symbols=document.getElementById("symbols");
const genBtn=document.getElementById("genBtn");
Span.textContent=inputSlider.value;
inputSlider.addEventListener('input',()=>{
Span.textContent=inputSlider.value;
})
genBtn.addEventListener('click',()=>{
passBox.value=generatePassword();
})
let upperChars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
let lowerChars="abcdefghijklmnopqrstuvwxyz";
let allNumbers="0123456789";
let allSymbols="~1@#$%^&*"
function generatePassword(){
let genPassword="";
let allChars="";
allChars+=lowercase.checked ? lowerChars:"";
allChars+=uppercase.checked ? upperChars:"";
allChars+=numbers.checked ? allNumbers:"";
allChars+=symbols.checked ? allSymbols:"";
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;
}