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

Password Strength textual message added #545

Merged
merged 1 commit into from
Oct 18, 2024
Merged
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
44 changes: 3 additions & 41 deletions signin.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
<div class="input-group">
<label for="password">Password</label>
<div class="password">
<input type="password" id="password" name="password" placeholder="Enter your password" oninput="checkPasswordStrength()" required>
<input type="password" id="password" name="password" placeholder="Enter your password">
<i class="fa-solid fa-eye-slash" id="togglePassword"></i>
</div>
</div>
<div class="strength-bar">
<!-- <div class="strength-bar">
<div id="strengthBar" class="strength-bar-inner"></div>
</div>
<p class="suggestion">
<small>Use special characters and numbers for a strong password</small>
</p>
</p> -->
<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>
</form>
Expand All @@ -69,44 +69,6 @@ <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
64 changes: 61 additions & 3 deletions signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
<div class="input-group">
<label for="password">Password</label>
<div class="password">
<input type="password" id="password" name="password" placeholder="Enter your password" required>
<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>
<button type="submit" class="signin-btn">Sign In</button>
</div>
</div>
<div class="strength-bar">
<div id="strengthBar" class="strength-bar-inner"></div>
</div>
<p class="suggestion">
<small id="strength_msg">Use special characters and numbers for a strong password</small>

</p>
<button type="submit" class="signin-btn">Sign Up</button>
<p class="signup-link">Already have an account? <a href="./signin.html">Sign in here</a></p>
</form>
</div>
Expand All @@ -66,6 +74,56 @@ <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');
const strength_text = document.getElementById('strength_msg');

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';
strength_text.textContent = "Password Strength : Very Weak";
break;
case 2:
strengthBar.style.width = '40%';
strengthBar.style.backgroundColor = 'orange';
strength_text.textContent = "Password Strength : Weak";
break;
case 3:
strengthBar.style.width = '60%';
strengthBar.style.backgroundColor = 'yellow';
strength_text.textContent = "Password Strength : Moderate";
break;
case 4:
strengthBar.style.width = '80%';
strengthBar.style.backgroundColor = 'lightgreen';
strength_text.textContent = "Password Strength : Good";
break;
case 5:
strengthBar.style.width = '100%';
strengthBar.style.backgroundColor = 'green';
strength_text.textContent = "Password Strength : Strong";
break;
default:
strengthBar.style.width = '0%';
strength_text.textContent ="Use special characters and numbers for a strong password";
break;
}
}


</script>
</body>
</html>