Skip to content

Instantly share code, notes, and snippets.

@Cordazar
Created January 17, 2014 10:17
Show Gist options
  • Save Cordazar/8471167 to your computer and use it in GitHub Desktop.
Save Cordazar/8471167 to your computer and use it in GitHub Desktop.
var passwordStrength = {
REGEX_PASSWORD_ONE_UPPERCASE : /^(?=.*[A-Z]).*$/, //Should contain one or more uppercase letters
REGEX_PASSWORD_ONE_LOWERCASE : /^(?=.*[a-z]).*$/, //Should contain one or more lowercase letters
REGEX_PASSWORD_ONE_NUMBER : /^(?=.*[0-9]).*$/, //Should contain one or more number
REGEX_PASSWORD_ONE_SYMBOL : /^(?=.*[!@#$%&_]).*$/, //Should contain one or more symbol
checkStrength: function (password) {
length = password.length;
//Will contain password strength
strength = 0;
if (length == 0) return "weak";
else if (length <= 5) strength++;
else if (length <= 10) strength += 2;
else strength += 3;
strength += this.REGEX_PASSWORD_ONE_UPPERCASE.test(password);
strength += this.REGEX_PASSWORD_ONE_LOWERCASE.test(password);
strength += this.REGEX_PASSWORD_ONE_SYMBOL.test(password);
strength += this.REGEX_PASSWORD_ONE_NUMBER.test(password);
if(strength <= 3) return "weak";
else if(3 < strength && strength < 6) return "moderate";
else return "strong";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment