Created
January 17, 2014 10:17
-
-
Save Cordazar/8471167 to your computer and use it in GitHub Desktop.
A JavaScript adaption of https://github.com/screeninteraction/RUBSPasswordStrength.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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