-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (39 loc) · 1.22 KB
/
script.js
File metadata and controls
45 lines (39 loc) · 1.22 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
function checkStrength() {
let password = document.getElementById("password").value;
let result = document.getElementById("result");
let hasUpper = false;
let hasLower = false;
let hasDigit = false;
let hasSpecial = false;
if (password.length < 8) {
result.innerText = "Password Strength: WEAK";
result.style.color = "red";
return;
}
for (let i = 0; i < password.length; i++) {
let ch = password[i];
if (ch >= 'A' && ch <= 'Z')
hasUpper = true;
else if (ch >= 'a' && ch <= 'z')
hasLower = true;
else if (ch >= '0' && ch <= '9')
hasDigit = true;
else
hasSpecial = true;
}
let score = 0;
if (hasUpper) score++;
if (hasLower) score++;
if (hasDigit) score++;
if (hasSpecial) score++;
if (score <= 1) {
result.innerText = "Password Strength: WEAK";
result.style.color = "red";
} else if (score <= 3) {
result.innerText = "Password Strength: MEDIUM";
result.style.color = "orange";
} else {
result.innerText = "Password Strength: STRONG";
result.style.color = "green";
}
}