om-password-strength-checker
Version:
A simple password strength checker utility
34 lines (24 loc) • 872 B
JavaScript
function checkPasswordStrength(password) {
let score = 0;
if (!password || typeof password !== "string") {
return { score, verdict: "Invalid password" };
}
if (password.length >= 8) score++;
if (password.length >= 12) score++;
if (/[a-z]/.test(password)) score++;
if (/[A-Z]/.test(password)) score++;
if (/[0-9]/.test(password)) score++;
if (/[^a-zA-Z0-9]/.test(password)) score++;
let verdict = "";
if (score <= 2) verdict = "Weak";
else if (score <= 4) verdict = "Moderate";
else if (score === 5) verdict = "Strong";
else if (score >= 6) verdict = "Very Strong";
return { score, verdict };
}
module.exports = { checkPasswordStrength };
// Test (only run when file is executed directly)
if (require.main === module) {
const result = checkPasswordStrength("Om@12345");
console.log(result);
}