Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added password strength indicator on signup page #492

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions signup/signup.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,28 @@ a{
}
input:focus{
outline: none;
}

#password-requirements p {
/* margin: 0; */
font-size: 0.8em;
color: grey;
}

#password-requirements .met {
color: green;
}



#password.weak {
border-color: red;
}

#password.medium {
border-color: orange;
}

#password.strong {
border-color: green;
}
11 changes: 9 additions & 2 deletions signup/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ <h2>Create an Account</h2>
<label>Email</label>
</div>
<div class="input-group">
<input type="password" required>
<input type="password" id="password" required>
<label>Password</label>
<div id="password-strength"></div>
<div id="password-requirements">
<p id="length-requirement">✔️ At least 6 characters</p>
<p id="uppercase-requirement">✔️ At least one uppercase letter</p>
<p id="number-requirement">✔️ At least one number</p>
<p id="special-requirement">✔️ At least one special character</p>
</div>
</div>
<button class="signup-btn" type="submit">Sign Up</button>
<button class="signup-btn" type="submit" disabled>Sign Up</button>
<div class="extra-links">
<button class="home-btn"><i class="fas fa-home"></i><a href="../index.html">Home</a></button>
<button class="login-btn"><i class="fas fa-sign-in-alt"></i><a href="../login/login.html">Login</a></button>
Expand Down
49 changes: 48 additions & 1 deletion signup/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ card.addEventListener("mouseleave", function () {
card.style.transform = "perspective(1000px)";
});


document.querySelector(".signup-form").addEventListener("submit", function (e) {
e.preventDefault(); // Prevent form submission

Expand Down Expand Up @@ -76,3 +75,51 @@ document.querySelector(".signup-form").addEventListener("submit", function (e) {
document.querySelector(".signup-form").reset(); // Clear the form fields
});

document.getElementById('password').addEventListener('input', function() {
const password = this.value;
const strengthDiv = document.getElementById('password-strength');
const lengthRequirement = document.getElementById('length-requirement');
const uppercaseRequirement = document.getElementById('uppercase-requirement');
const numberRequirement = document.getElementById('number-requirement');
const specialRequirement = document.getElementById('special-requirement');
const signupButton = document.querySelector('.signup-btn');
let strength = '';
let strengthClass = '';

// Check each requirement
const lengthMet = password.length >= 6;
const uppercaseMet = /[A-Z]/.test(password);
const numberMet = /[0-9]/.test(password);
const specialMet = /[!@#$%^&*]/.test(password);

// Update requirement styles
lengthRequirement.classList.toggle('met', lengthMet);
uppercaseRequirement.classList.toggle('met', uppercaseMet);
numberRequirement.classList.toggle('met', numberMet);
specialRequirement.classList.toggle('met', specialMet);

// Determine strength
if (lengthMet) {
if (uppercaseMet && numberMet && specialMet) {
strength = 'Strong';
strengthClass = 'strong';
} else if (uppercaseMet || numberMet || specialMet) {
strength = 'Medium';
strengthClass = 'medium';
} else {
strength = 'Weak';
strengthClass = 'weak';
}
} else {
strength = 'Too short';
strengthClass = 'weak';
}

// Update strength message and input box color
strengthDiv.textContent = strength;
strengthDiv.className = strengthClass;
this.className = strengthClass;

// Enable/disable signup button
signupButton.disabled = strength !== 'Strong';
});