forked from Antidoteprashant/Project-_Archon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (38 loc) · 1.61 KB
/
Copy pathscript.js
File metadata and controls
48 lines (38 loc) · 1.61 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
46
47
48
const overlay = document.querySelector(".overlay");
const authContainer = document.querySelector(".auth-container");
// Target the password input specifically by its id from register.html
const passInput = document.querySelector("#password");
const passGroup = passInput ? passInput.closest('.form-group') : null;
let errorMessage = null;
if (overlay) {
overlay.addEventListener("click", () => {
overlay.classList.add("hidden");
window.location.href = "index.html";
});
}
if (authContainer) {
authContainer.addEventListener("click", (event) => {
event.stopPropagation();
});
}
//add an event listener that listens to the input that the user types in the password field and checks if the password is strong or not, and generate an error message if the password is weak.
if (passInput) {
passInput.addEventListener("input", () => {
const password = passInput.value;
const isWeak = password.length < 8 || !/[!@#$%^&*]/.test(password) || !/[A-Z]/.test(password);
if (!errorMessage && passGroup) {
errorMessage = document.createElement("p");
errorMessage.classList.add("error-message");
errorMessage.style.color = "red";
errorMessage.style.marginTop = "8px";
passGroup.appendChild(errorMessage);
}
if (isWeak && errorMessage) {
errorMessage.textContent = "This password is weak, please input a strong password.";
errorMessage.style.display = "block";
} else if (errorMessage) {
errorMessage.textContent = "";
errorMessage.style.display = "none";
}
});
}