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

feat: password strength checker #410

Closed
wants to merge 1 commit 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
21 changes: 21 additions & 0 deletions assets/css/signin.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,24 @@ p {
font-size: 14px;
}
}

.strength-bar {
width: 100%;
height: 3px;
background-color: #ddd;
margin-top: 10px;
}
.strength-bar-inner {
height: 100%;
width: 0%;
background-color: red;
transition: width 0.3s ease;
}
#pass_login{
display: flex;
align-items: center;
justify-content: space-between;
}
#pass_login i{
padding-left: 200px;
}
58 changes: 54 additions & 4 deletions signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
</div>
<div class="input-group">
<label for="password">Password</label>
<div class="password">
<input type="password" id="password" name="password" placeholder="Enter your password" required>
<i class="fa-solid fa-eye-slash" id="togglePassword"></i>
</div>
<div class="password" id="pass_login">
<div id="pass_login">
<input type="password" id="password" name="password" placeholder="Enter your password" oninput="checkPasswordStrength()" required>
<i class="fa-solid fa-eye-slash" id="togglePassword" ></i>

</div>
</div>
<div class="strength-bar">
<div id="strengthBar" class="strength-bar-inner"></div>
</div>
<ul class="bullet-points">
<li><small>Use special characters and numbers for strong password</small></li>
<li><small>Use special characters and numbers for strong password</small></li>
<li><small>Use special characters and numbers for strong password</small></li>
<li><small>Use special characters and numbers for strong password</small></li>
</ul>
</div>
<button type="submit" class="signin-btn">Sign In</button>
<p class="signup-link">Don't have an account? <a href="./signup.html">Sign up here</a></p>
Expand All @@ -51,6 +63,44 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
this.classList.toggle("fa-eye");
});

function checkPasswordStrength() {
const password = document.getElementById('password').value;
const strengthBar = document.getElementById('strengthBar');
let strength = 0;

if (password.length >= 8) strength += 1;
if (/[A-Z]/.test(password)) strength += 1;
if (/[a-z]/.test(password)) strength += 1;
if (/[0-9]/.test(password)) strength += 1;
if (/[\W]/.test(password)) strength += 1;

switch (strength) {
case 1:
strengthBar.style.width = '20%';
strengthBar.style.backgroundColor = 'red';
break;
case 2:
strengthBar.style.width = '40%';
strengthBar.style.backgroundColor = 'orange';
break;
case 3:
strengthBar.style.width = '60%';
strengthBar.style.backgroundColor = 'yellow';
break;
case 4:
strengthBar.style.width = '80%';
strengthBar.style.backgroundColor = 'lightgreen';
break;
case 5:
strengthBar.style.width = '100%';
strengthBar.style.backgroundColor = 'green';
break;
default:
strengthBar.style.width = '0%';
break;
}
}

</script>

</body>
Expand Down