Created
February 9, 2010 03:06
-
-
Save guilherme/298879 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Password < String | |
POSSIBLE_STRENGTHS = { 1 => "senha fraca", 2 => "senha média", 3 => "senha forte" } | |
def self.check_strength(password) | |
strength = 1 | |
if password.length >= 8 || (password.length > 6 && password =~ /[a-z]/ && password =~ /[0-9]/) | |
strength+=1 | |
end | |
if password.length > 12 && password =~ /[a-z]/ && password =~ /[A-Z]/ && password =~ /[0-9]/ && password =~ /[^a-zA-Z0-9_\s]/ | |
strength+=1 | |
end | |
POSSIBLE_STRENGTHS[strength] | |
end | |
def strength | |
Password.check_strength(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment