|
16 | 16 | </script>
|
17 | 17 |
|
18 | 18 | <script>
|
19 |
| - let password = document.getElementById('password'); |
| 19 | + const password = document.getElementById('password'); |
20 | 20 | const indicator = document.querySelector(".strength-indicator");
|
21 |
| - const input = document.querySelector("input"); |
| 21 | + const text = document.querySelector(".strength-text"); |
22 | 22 | const weak = document.querySelector(".weak");
|
23 | 23 | const medium = document.querySelector(".medium");
|
24 | 24 | 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; |
29 | 32 |
|
30 | 33 | password.addEventListener('keyup', function () {
|
31 | 34 | console.log(password.value);
|
| 35 | + let type = 0; |
| 36 | + |
32 | 37 | if (password.value !== "") {
|
33 | 38 | indicator.style.display = "flex";
|
34 | 39 | 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) { |
39 | 46 | weak.classList.add("active");
|
40 | 47 | text.style.display = "block";
|
41 | 48 | text.textContent = "Your password is too weak";
|
42 | 49 | text.classList.add("weak");
|
| 50 | + button.disabled = true; |
43 | 51 | }
|
44 |
| - if (no === 2) { |
| 52 | + if (type === 2) { |
45 | 53 | medium.classList.add("active");
|
46 | 54 | text.textContent = "Your password is not that strong";
|
47 | 55 | text.classList.add("medium");
|
| 56 | + button.disabled = true; |
48 | 57 | } else {
|
49 | 58 | medium.classList.remove("active");
|
50 | 59 | text.classList.remove("medium");
|
51 | 60 | }
|
52 |
| - if (no === 3) { |
| 61 | + if (type === 3) { |
53 | 62 | weak.classList.add("active");
|
54 | 63 | medium.classList.add("active");
|
55 | 64 | strong.classList.add("active");
|
56 | 65 | text.textContent = "Your password is strong";
|
57 | 66 | text.classList.add("strong");
|
| 67 | + button.disabled = false; |
58 | 68 | } else {
|
59 | 69 | strong.classList.remove("active");
|
60 | 70 | text.classList.remove("strong");
|
61 | 71 | }
|
62 | 72 | } else {
|
63 | 73 | indicator.style.display = "none";
|
64 | 74 | text.style.display = "none";
|
| 75 | + button.disabled = true; |
65 | 76 | }
|
66 |
| - }) |
| 77 | + }); |
67 | 78 | </script>
|
68 | 79 | {% endif %}
|
69 | 80 |
|
|
0 commit comments