I'm trying out a strong password detection task 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. We need to test the string against multiple regex patterns to validate its strength.
Here's my proposed code for the same:
import re
def password_detect(exp):
if len(exp) >= 8:
passRegex = re.compile('r[(a-z)+(A-Z)+(0-9)+]')
mo = passRegex.search(exp)
if mo.group() != None:
print("Password is strong")
else:
print("Password is not strong")
else:
print("Password length is not strong")
It returns this traceback:
Traceback (most recent call last):
File "<ipython-input-245-4202435a0efb>", line 1, in <module>
password_detect('oldG2020')
File "<ipython-input-243-39585a6ade11>", line 5, in password_detect
if mo.group() != None:
AttributeError: 'NoneType' object has no attribute 'group'
Which is a NoneType being returned? It seems to follow the rules. Thanks.