我已经设置了一个程序来更改“密码”。我让它检查它是否至少有 8 个字符、包含大写字母和数字,如果不满足此条件,它会再次要求输入密码。除了检查号码之外,我一切正常,我想知道是否有人可以提供帮助。
npwv = 1
while npwv == 1:
npw = input("Please enter new password.")
npwc = input ("Please confirm new password")
if npwc == npw:
if npwc.isupper()== False:
if npwc.islower()== False:
if len(npwc) >= 8:
if str.isdigit(npwc) == True:
npw=npwc
print("Your password has been changed")
else:
print("Your password must contain a number")
npwv = 1
else:
print("Your password must contain at least 8 characters.")
npwv = 1
else:
print("Your password must contain at least 1 upper case character.")
npwv = 1
else:
print ("Passwords don't match")
npwv = 1
您正在检查密码本身是否完全大写或由数字组成。您需要检查密码中的字符是否符合此条件。
has_upper = any([c.isupper() for c in npwc])
has_digit = any([c.isdigit() for c in npwc])
您还可以使用正则表达式。
顺便说一句,你应该更喜欢getpass从用户那里获取密码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)