<!DOCTYPE html>
<html>
<head>
<title>Password Strength Validation Example</title>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<h2>Password Strength Validation Example</h2>
<form id="passwordForm" onsubmit="return validatePassword()">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<span id="passwordError" class="error"></span>
<br>
<input type="submit" value="Submit">
</form>
<script src="zxcvbn.js"></script>
<script>
function validatePassword() {
var passwordInput = document.getElementById('password');
var password = passwordInput.value;
var passwordError = document.getElementById('passwordError');
// Reset error message
passwordError.innerHTML = "";
// Password Strength Check using zxcvbn
var result = zxcvbn(password);
// Display password strength feedback to the user
if (result.score < 3) {
passwordError.innerHTML = "Choose a stronger password";
return false;
}
// Form is valid
alert("Password submitted successfully!");
return true;
}
</script>
</body>
</html>
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.