I am trying to make a regular expression that can check the strength of password. A password is considered to be strong if:
- It has minimum length of 8 characters
- It must contains minimum 2 Upper case and 2 Lower case letter
- It must contains minimum 2 digits
- It must contains minimum 2 special characters from
$,%,&,!,#
This is what i have done:
# Strong Password Checker
import re
password_regex = re.compile(r'[(A-Z){2}(a-z){2}(0-9){2}($%&!#){2}]{8,}')
if password_regex.match('testpassword'):
print("Your password is strong")
else:
print("Your password is weak")
The password supplies to this code is not strong but, it doesn't detect it as weak password, Instead it identifies it as strong password.
Initially i am learning regular expression, so i want to keep everything simple and clear, if someone help it would be really appreciated.