Created
September 24, 2023 14:38
-
-
Save oshyam/1ad31bc0c0ad216dc37dd3761cae7e42 to your computer and use it in GitHub Desktop.
Password Indicator using plain js and html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Password Strength Indicator Lab</title> | |
<style> | |
/* Add your CSS here */ | |
#strength { | |
font-weight: bold; | |
margin-top: 10px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Password Strength Indicator Lab</h1> | |
<label for="password">Enter a password:</label> | |
<input type="password" id="password" /> | |
<p id="strength"> | |
Password Strength: <span id="strengthIndicator">Weak</span> | |
</p> | |
<script> | |
// Add your JavaScript here | |
const passwordInput = document.getElementById("password"); | |
const strengthIndicator = document.getElementById("strengthIndicator"); | |
// Add an event listener to check password strength on input | |
passwordInput.addEventListener("input", () => { | |
const password = passwordInput.value; | |
const strength = calculatePasswordStrength(password); | |
// Update the strength indicator based on password strength | |
strengthIndicator.textContent = strength; | |
}); | |
// Function to calculate password strength (customize as needed) | |
function calculatePasswordStrength(password) { | |
if (password.length < 4) { | |
return "Very Weak"; | |
} else if (password.length >= 4 && password.length < 8) { | |
return "Weak"; | |
} else if (password.length >= 8 && password.length < 12) { | |
return "Medium"; | |
} else if (password.length >= 12 && password.length < 16) { | |
return "Strong"; | |
} else { | |
return "Very Strong"; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment