作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经设置了一个程序来更改“密码”。我让它检查它是否至少有 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
从用户那里获取密码。
关于python - 如何在 python 中检查 "password"中的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41941421/
我是一名优秀的程序员,十分优秀!