-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
85 lines (63 loc) · 2.4 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const inputSlider = document.getElementById("inputSlider");
const sliderValue = document.getElementById("sliderValue");
const passBox = document.getElementById("passBox");
const lowercaseE1 = document.getElementById("lowercase");
const uppercaseE1 = document.getElementById("uppercase");
const numbersE1 = document.getElementById("numbers");
const symbolsEl = document.getElementById("symbols");
const generateBtn = document.getElementById("genBtn");
const copyBtn = document.getElementById("copyIcon");
const passIndicator = document.getElementById("passIndicator");
const lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
const uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const numbers = "0123456789";
const symbols = "!@#%^&*()_+-=[]{}\\||;':\",./<>?";
sliderValue.textContent = inputSlider.value;
inputSlider.addEventListener('input',()=>{
sliderValue.textContent = inputSlider.value;
generatePassword();
})
function generatePassword(){
const length = inputSlider.value;
let charecters = "";
let password = "";
charecters += lowercaseE1.checked ? lowercaseLetters : "";
charecters += uppercaseE1.checked ? uppercaseLetters : "";
charecters += numbersE1.checked ? numbers : "";
charecters += symbolsEl.checked ? symbols : "";
for(let i = 0 ; i < length ; i++){
password += charecters.charAt(Math.floor(Math.random() * charecters.length));
}
passBox.value = password;
updatePasswordIndicator();
}
generateBtn.addEventListener("click",()=>{
generatePassword();
});
function updatePasswordIndicator(){
const passwordStrength = getPasswordStrength(passBox.value);
console.log(passwordStrength);
passIndicator.className = "pass-indicator " + passwordStrength;
console.log(passIndicator.className);
}
function getPasswordStrength(password){
if(password.length <= 10){
return "weak";
}else if(password.length <=20){
return "medium";
}else{
return "strong";
}
}
window.addEventListener('DOMContentLoaded',()=>{
updatePasswordIndicator();
});
copyBtn.addEventListener("click",()=>{
if(passBox.value != "" || passBox.value.length >= 1){
navigator.clipboard.writeText(passBox.value);
copyBtn.innerText = "check";
setTimeout(()=>{
copyBtn.innerHTML = "content_copy";
}, 3000);
}
});