首页 > 解决方案 > 密码验证 - 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")

有关如何解决此问题的任何想法,谢谢

标签: pythonvalidationpasswords

解决方案


我运行它并输入“测试”,它说“密码很好”。我怀疑你的意思是:

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")

因为否则您将执行错误的密码。


推荐阅读