I have the following code to test a password for strength:
import string
def golf(password):
if len(password) >= 10:
if any(char.isdigit() for char in password):
if any(string.punctuation for char in password):
if any(char.isalpha() for char in password):
if any(char.isupper() for char in password):
if any(char.islower() for char in password):
return True
return False
I know it can be done better! It needs to test for the following ...
The password will be considered strong enough if it has at least 10 characters contains at least one digit contains at least one uppercase letter contains at least one lowercase letter. The password may only contain ASCII Latin letters or digits, but no punctuation symbols.
EDIT
OK for anyone else i got it down to the following with regex.
import re
def golf(password):
return re.match( r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.{10,30}).+$', password)
Apparently it can still be shorter...