Skip to content

Commit c08f9f8

Browse files
committed
feat(auth.register): allow submitting for strong password only
1 parent b02f6f8 commit c08f9f8

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

templates/auth/register.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ <h1 class="mb-4">Be Advised</h1>
9797
</ul>
9898

9999
<div class="btn-grp">
100-
<input type="submit" value="Register" class="btn btn-outline-inverse btn-xl">
100+
<input type="submit" value="Register" id="submit" class="btn btn-outline-inverse btn-xl">
101101
</div>
102102
</form>
103103

templates/scripts.html

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,65 @@
1616
</script>
1717

1818
<script>
19-
let password = document.getElementById('password');
19+
const password = document.getElementById('password');
2020
const indicator = document.querySelector(".strength-indicator");
21-
const input = document.querySelector("input");
21+
const text = document.querySelector(".strength-text");
2222
const weak = document.querySelector(".weak");
2323
const medium = document.querySelector(".medium");
2424
const strong = document.querySelector(".strong");
25-
const text = document.querySelector(".strength-text");
26-
let regExpWeak = /[a-z]/;
27-
let regExpMedium = /\d+/;
28-
let regExpStrong = /.[!@#$%^&*?_~()]/;
25+
26+
const regExpWeak = /[a-z]/;
27+
const regExpMedium = /\d+/;
28+
const regExpStrong = /.[!@#$%^&*?_~()]/;
29+
30+
const button = document.getElementById('submit');
31+
button.disabled = true;
2932

3033
password.addEventListener('keyup', function () {
3134
console.log(password.value);
35+
let type = 0;
36+
3237
if (password.value !== "") {
3338
indicator.style.display = "flex";
3439
indicator.style.margin = "0 auto";
35-
if (password.value.length <= 8 && (password.value.match(regExpWeak) || password.value.match(regExpMedium) || password.value.match(regExpStrong))) no = 1;
36-
if (password.value.length >= 8 && ((password.value.match(regExpWeak) && password.value.match(regExpMedium)) || (password.value.match(regExpMedium) && password.value.match(regExpStrong)) || (password.value.match(regExpWeak) && password.value.match(regExpStrong)))) no = 2;
37-
if (password.value.length >= 8 && password.value.match(regExpWeak) && password.value.match(regExpMedium) && password.value.match(regExpStrong)) no = 3;
38-
if (no === 1) {
40+
41+
if (password.value.length <= 8 && (password.value.match(regExpWeak) || password.value.match(regExpMedium) || password.value.match(regExpStrong))) type = 1;
42+
if (password.value.length >= 8 && ((password.value.match(regExpWeak) && password.value.match(regExpMedium)) || (password.value.match(regExpMedium) && password.value.match(regExpStrong)) || (password.value.match(regExpWeak) && password.value.match(regExpStrong)))) type = 2;
43+
if (password.value.length >= 8 && password.value.match(regExpWeak) && password.value.match(regExpMedium) && password.value.match(regExpStrong)) type = 3;
44+
45+
if (type === 1) {
3946
weak.classList.add("active");
4047
text.style.display = "block";
4148
text.textContent = "Your password is too weak";
4249
text.classList.add("weak");
50+
button.disabled = true;
4351
}
44-
if (no === 2) {
52+
if (type === 2) {
4553
medium.classList.add("active");
4654
text.textContent = "Your password is not that strong";
4755
text.classList.add("medium");
56+
button.disabled = true;
4857
} else {
4958
medium.classList.remove("active");
5059
text.classList.remove("medium");
5160
}
52-
if (no === 3) {
61+
if (type === 3) {
5362
weak.classList.add("active");
5463
medium.classList.add("active");
5564
strong.classList.add("active");
5665
text.textContent = "Your password is strong";
5766
text.classList.add("strong");
67+
button.disabled = false;
5868
} else {
5969
strong.classList.remove("active");
6070
text.classList.remove("strong");
6171
}
6272
} else {
6373
indicator.style.display = "none";
6474
text.style.display = "none";
75+
button.disabled = true;
6576
}
66-
})
77+
});
6778
</script>
6879
{% endif %}
6980

0 commit comments

Comments
 (0)