I am trying to write a program 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. So far, I have the following code. I have spent hours tinkering the regular expression, however I cant make it so that it will pass. Each time I make a change, it seems a strong password gets marked as weak, or a weak as strong. Any idea how I can improve this?
import re
pass2Regex = re.compile(r'''
\d*
[a-zA-Z]*
\d*
[a-zA-Z]*
''',re.VERBOSE)
text = raw_input("enter your password\n")
if len(text) >= 8:
search = pass2Regex.findall(text)
if text in search:
print "%s is a strong password" % (text)
else:
print "%s is a weak password" % (text)
else:
print "%s is a weak password" % (text)
For example, right now if the password were "231242441", it would be marked as a strong password even though there are no letters. Furthermore, When I try a + instead of a * it will only accept passwords that start with a digit, etc..
Thanks for the help