-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
91 lines (78 loc) · 3.97 KB
/
mod.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
document.addEventListener("DOMContentLoaded", function () {
const container = document.getElementById("container");
const loginButton = document.getElementById("login");
const registerButton = document.getElementById("register");
loginButton.addEventListener("click", () => {
container.classList.remove("active");
});
registerButton.addEventListener("click", () => {
container.classList.add("active");
});
const signUpForm = document.getElementById("signUpForm");
const signInForm = document.getElementById("signInForm");
signUpForm.addEventListener("submit", function (event) {
event.preventDefault();
const name = signUpForm.querySelector('input[placeholder="Name"]').value;
const email = signUpForm.querySelector('input[placeholder="Email"]').value;
const password = signUpForm.querySelector('input[placeholder="Password"]').value;
if (name && email && password) {
if (password.length >= 8) {
alert("Sign up successful!");
} else {
alert("Password must be at least 8 characters long.");
}
} else {
alert("All fields are required.");
}
});
signInForm.addEventListener("submit", function (event) {
event.preventDefault();
const email = signInForm.querySelector('input[placeholder="Email"]').value;
const password = signInForm.querySelector('input[placeholder="Password"]').value;
const rememberMe = document.getElementById('rememberMe') ? document.getElementById('rememberMe').checked : false;
if (email && password) {
alert(`Sign in successful! Remember Me: ${rememberMe}`);
} else {
alert("All fields are required.");
}
});
// Show/hide password functionality
const togglePasswordVisibility = (toggleButtonId, passwordFieldId) => {
const toggleButton = document.getElementById(toggleButtonId);
const passwordField = document.getElementById(passwordFieldId);
toggleButton.addEventListener('click', () => {
const type = passwordField.type === 'password' ? 'text' : 'password';
passwordField.type = type;
toggleButton.classList.toggle('fa-eye-slash');
});
};
togglePasswordVisibility('toggleSignUpPassword', 'signUpPassword');
togglePasswordVisibility('toggleSignInPassword', 'signInPassword');
// Password strength meter for sign-up form
document.getElementById('signUpPassword').addEventListener('input', function () {
const passwordStrength = document.getElementById('signUpPasswordStrength');
const password = this.value;
let strength = 0;
if (password.length >= 8) strength++;
if (password.match(/[a-z]/) && password.match(/[A-Z]/)) strength++;
if (password.match(/[0-9]/)) strength++;
if (password.match(/[^a-zA-Z0-9]/)) strength++; // Special character
switch (strength) {
case 0:
passwordStrength.innerHTML = "";
break;
case 1:
passwordStrength.innerHTML = '<div style="height:100%; width:100%; color:aliceblue; background-color:red;"> Weak </div>';
break;
case 2:
passwordStrength.innerHTML = '<div style="height:100%; width:100%; color:aliceblue;background-color:orange"> Medium </div>';
break;
case 3:
passwordStrength.innerHTML = '<div style="height:100%; width:100%; color:aliceblue;background-color:green;"> Strong </div>';
break;
case 4:
passwordStrength.innerHTML = '<div style="height:100%; width:100%; color:aliceblue;background-color:blue;"> Excellent </div>';
break;
}
});
});