python - 密码验证 - python
问题描述
我正在尝试编写代码来验证密码。但是它不起作用,关于如何解决这个问题的任何想法?
password = input("Please enter password: ")
length = False
digit = False
capital = False
length = len(password)
if length > 6:
length = True
#print("Length Good")
for count in password:
if count.isdigit():
digit = True
#print ("Contains digit")
for count in password:
if count.isupper():
capital = True
#print ("Contains a capital")
if length != True and digit != True and capital != True:
print("Password is good")
else:
print("Bad password")
有关如何解决此问题的任何想法,谢谢
解决方案
我运行它并输入“测试”,它说“密码很好”。我怀疑你的意思是:
password = input("Please enter password: ")
length = False
digit = False
capital = False
length = len(password)
if length > 6:
length = True
#print("Length Good")
for count in password:
if count.isdigit():
digit = True
#print ("Contains digit")
for count in password:
if count.isupper():
capital = True
#print ("Contains a capital")
if length == True and digit == True and capital == True:
print("Password is good")
else:
print("Bad password")
因为否则您将执行错误的密码。
推荐阅读
- git - 如何从 Github 组织的所有存储库中获取提交
- asp.net-core - 如何为 FROM 命令生成 docker 映像路径
- python - 如何在 VS Code 中为选择的文件、glob 或类似文件关闭排序导入?
- python - 人脸识别opencv得到类型元组错误
- matlab - 带有 textdat 的文本文件包含字符的单元格
- c# - 使用 ExcelPackage 导入 XLSX 文件会引发错误 .NET CORE
- django - 将两个值传递给模板标签
- python - 如何从带有变量的 sqlite 中选择
- openstack - openstack中实例的降级风格
- python - 如何从视图或中间件获取模型的 IP 地址?