Skip to content

Instantly share code, notes, and snippets.

@maliqq
Created March 5, 2010 11:53
Show Gist options
  • Save maliqq/322661 to your computer and use it in GitHub Desktop.
Save maliqq/322661 to your computer and use it in GitHub Desktop.
def password_strength(value)
strength = 0
case value.size
when 5..7
strength += 6
when 8..9
strength += 12
else
strength += 18 if value.size > 10
end
strength += 1 if value =~ /[a-z]/
strength += 5 if value =~ /[A-Z]/
strength += 5 if value =~ /\d+/
strength += 7 if value =~ /(.*[0-9].*[0-9].*[0-9])/
strength += 5 if value =~ /.[!,@,#,$,%,^,&,*,?,_,~]/
strength += 7 if value =~ /(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/
strength += 2 if value =~ /([a-z].*[A-Z])|([A-Z].*[a-z])/
strength += 3 if value =~ /([a-zA-Z])/ && value =~ /([0-9])/
strength += 3 if value =~ /([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/
return strength
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment