-
-
Save Hasstrup/cb874cd94b97b04b4ec29a0e1f384b65 to your computer and use it in GitHub Desktop.
Password strength with regex in Ruby
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
# example of using lookahead assertion to test password strength | |
# test if a given string contains at least a lowercase letter, a uppercase, a digit, a special char and 8+ chars | |
strong = "123ABCabc-" | |
strong[/^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,}$/] | |
# test if a given string contains at least a lowercase letter, a uppercase, a digit and 8+ chars | |
medium = "123ABCabc" | |
medium[/^(?=.*[a-zA-Z])(?=.*[0-9]).{8,}$/] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment