I am writing a function that is checking if the password meets requirements. The requirements are:
- At least 8 characters
- At least 1 upper case letter
- At least 1 lower case letter
- At least 1 number
- At least 1 of these special character: @$!#%*?&
Here is my code:
passwordCriteria = re.compile(r'''
(?=.*[a-z])
(?=.*[A-Z])
(?=.*\d)
(?=.*[@$!%*#?&])
[A-Za-z\d@$!#%*?&]{8,}$
''', re.VERBOSE)
If I enter the password: Newyork@1995. The password should be meet the requirements.
However, when I remove this condition from the code above (?=.*\d)
. The password still meets the requirements apparently.
How is that possible? doesn't this lookahead check (?=.*\d)
ensure that there is at least 1 number in the password?