Skip to content

Instantly share code, notes, and snippets.

@Iteratix
Created August 27, 2012 22:28
Show Gist options
  • Save Iteratix/3492947 to your computer and use it in GitHub Desktop.
Save Iteratix/3492947 to your computer and use it in GitHub Desktop.
passwordStrength: function(password) {
if (typeof password == 'undefined') {
return 'none';
}
var score = 0;
score += Math.min(password.length, 10);
var types = 0;
if ((/[A-Z]/).test(password)) {types += 1;}
if ((/[a-z]/).test(password)) {types += 1;}
if ((/[0-9]/).test(password)) {types += 1;}
if ((/[\!@#\$%^&*\(\)<>,.\/\?\\{}\[\]|`~]/).test(password)) {types += 1;}
if (types == 2) {
score += 7;
}
else if (types == 3) {
score += 10;
}
else if (types == 4) {
score += 15;
}
if (score >= 20) {
return 'high';
}
else if (score >= 10) {
return 'med';
}
else if (score > 0) {
return 'low';
}
return 'none';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment