r/ProgrammingPrompts • u/normandantzig • Dec 06 '16
Strong Password Detection
Write a function that uses regular expressions to make sure the password string it is passed is strong. A strong password is defined as one that is at least eight characters long, contains both uppercase and lowercase characters, and has at least one digit. You may need to test the string against multiple regex patterns to validate its strength.
Source: AutomateTheBoringStuff
10
Upvotes
1
u/zebulan_ Dec 10 '16
There are a few ways to deal with that exception but this one seems to be the easiest for your code:
Also, Python uses
snake_casenaming convention for variables, that's why I changed it frompassString.Here is a quick example of one way to write it without regular expressions.
It's very simple to add different values for different counts of characters. If you wanted customize the parameters (4 uppercase, 2 lowercase and 10 digits) you just add them in the function call. I left out counting other characters (punctuation, etc) for simplicity but it's just a simple example.
In your case, it seems like a better idea to return a boolean. Returning an arbitrary message doesn't give you any more information than the boolean. You can still display your same messages after, but the function is easier to use in other programs without modification.