在此程序中,我们将密码作为字母数字字符和特殊字符的组合,并在几个条件的帮助下检查密码是否有效。
密码验证的主要条件:
1.最少8个字符。
2.字母必须介于[az]之间
3.至少一个字母应为大写[AZ]
4.[0-9]之间至少有1个数字或数字。
5.来自[_或@或$]的至少1个字符。
示例:import re
password = "R@m@_f0rtu9e$"
flag = 0
while True:
if (len(password)<8):
flag = -1
break
elif not re.search("[a-z]", password):
flag = -1
break
elif not re.search("[A-Z]", password):
flag = -1
break
elif not re.search("[0-9]", password):
flag = -1
break
elif not re.search("[_@$]", password):
flag = -1
break