Skip to content

Commit 931cb1e

Browse files
committed
Update 2
1 parent 452c662 commit 931cb1e

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

Password Strength Meter/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="container">
1313
<header>Password Strength Meter<br></header>
1414
<form action="#">
15-
<div class="field"><input onkeyup="trigger()" type="password" placeholder="Type your password"><span class="showBtn">SHOW</span></div>
15+
<div class="field"><input id="trigger" type="password" placeholder="Type your password"><span class="showBtn">SHOW</span></div>
1616
<!--field-->
1717
<div class="indicator">
1818
<span class="weak"></span>

Password Strength Meter/script.js

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,62 @@ let regExpStrong = /.[!,@,#,$,%,^,&,*,(,)]/;
1212

1313

1414

15-
function trigger() {
15+
document.getElementById("trigger").addEventListener("keyup", function() {
1616
if (input.value != "") {
1717
indicator.style.display = "flex";
1818

19-
if (input.value.length <= 3 && (input.value.match(regExpWeak) || input.value.match(regExpMedium) || input.value.match(regExpStrong))) no = 1;
2019

21-
if (input.value.length >= 6 && ((input.value.match(regExpWeak) && input.value.match(regExpMedium)) || (input.value.match(regExpMedium) && input.value.match(regExpStrong)) || (input.value.match(regExpWeak) && input.value.match(regExpStrong)))) no = 2;
20+
} else {
21+
indicator.style.display = "none";
22+
text.style.display = "none";
23+
showBtn.style.display = "none";
24+
}
2225

23-
if (input.value.length >= 6 && input.value.match(regExpWeak) && input.value.match(regExpMedium) && input.value.match(regExpStrong)) no = 3;
26+
if (input.value.length <= 3 && (input.value.match(regExpWeak) || input.value.match(regExpMedium) || input.value.match(regExpStrong))) no = 1;
2427

25-
if (no == 1) {
26-
weak.classList.add("active");
27-
text.style.display = "block";
28-
text.textContent = "Your password is too weak";
29-
text.classList.add("weak");
30-
}
28+
if (input.value.length >= 6 && ((input.value.match(regExpWeak) && input.value.match(regExpMedium)) || (input.value.match(regExpMedium) && input.value.match(regExpStrong)) || (input.value.match(regExpWeak) && input.value.match(regExpStrong)))) no = 2;
3129

32-
if (no == 2) {
33-
medium.classList.add("active");
34-
text.textContent = "Your password is average";
35-
text.classList.add("medium");
36-
} else {
37-
medium.classList.remove("active");
38-
text.classList.remove("medium");
39-
}
30+
if (input.value.length >= 6 && input.value.match(regExpWeak) && input.value.match(regExpMedium) && input.value.match(regExpStrong)) no = 3;
4031

41-
if (no == 3) {
42-
medium.classList.add("active");
43-
strong.classList.add("active");
44-
text.style.display = "block";
45-
text.textContent = "Your password is strong";
46-
text.classList.add("strong");
47-
} else {
48-
strong.classList.remove("active");
49-
text.classList.remove("strong");
50-
}
32+
if (no == 1) {
33+
weak.classList.add("active");
34+
text.style.display = "block";
35+
text.textContent = "Your password is too weak";
36+
text.classList.add("weak");
37+
}
5138

52-
showBtn.style.display = "block";
53-
showBtn.onclick = function() {
54-
if (input.type == "password") {
55-
input.type = "text";
56-
showBtn.textContent = "HIDE";
57-
showBtn.style.color = "#23ad5c";
58-
} else {
59-
input.type = "password";
60-
showBtn.textContent = "SHOW";
61-
showBtn.style.color = "#000";
62-
}
63-
}
39+
if (no == 2) {
40+
medium.classList.add("active");
41+
text.textContent = "Your password is average";
42+
text.classList.add("medium");
6443
} else {
65-
indicator.style.display = "none";
66-
text.style.display = "none";
67-
showBtn.style.display = "none";
44+
medium.classList.remove("active");
45+
text.classList.remove("medium");
46+
}
47+
48+
if (no == 3) {
49+
medium.classList.add("active");
50+
strong.classList.add("active");
51+
text.style.display = "block";
52+
text.textContent = "Your password is strong";
53+
text.classList.add("strong");
54+
} else {
55+
strong.classList.remove("active");
56+
text.classList.remove("strong");
6857
}
69-
}
58+
59+
showBtn.style.display = "block";
60+
showBtn.onclick = function() {
61+
if (input.type == "password") {
62+
input.type = "text";
63+
showBtn.textContent = "HIDE";
64+
showBtn.style.color = "#23ad5c";
65+
} else {
66+
input.type = "password";
67+
showBtn.textContent = "SHOW";
68+
showBtn.style.color = "#000";
69+
}
70+
}
71+
72+
});
7073

0 commit comments

Comments
 (0)