Password Strength Checker (JS)
28. Password Strength Checker (JS)
=================================
function checkPasswordStrength(password) {
let score = 0;
if (password.length >= 8) 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++;
const strength = ['Weak', 'Fair', 'Good', 'Strong', 'Very Strong'][score] || 'Weak';
return { score, strength, message: `Password strength: ${strength}` };
}
// Usage
console.log(checkPasswordStrength('PasteText123!')); // {score:4, strength:'Strong'}
Featured
Advertisement
Category
Action