Skip to content

Instantly share code, notes, and snippets.

@guilherme
Created February 9, 2010 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilherme/298879 to your computer and use it in GitHub Desktop.
Save guilherme/298879 to your computer and use it in GitHub Desktop.
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