如何显示密码测试仪输入的所有错误

问题描述 投票:0回答:1

我的程序工作得非常好,但没有用密码返回一切错误,它只会返回一个问题。

示例:密码为ASD123(问题少于10个字符,没有符号)。程序只返回“密码小于10个字符”

passwordisokk = True

def passwordisOK():
    while True:
        passwordisokk = input("Please enter a password so we can validate:")
        if len(passwordisokk) < 10:
            print(" Your password should be 10 characters,please enter more characters")
            passwordisokk = False
            print(passwordisokk)
        elif re.search("[0-9]",passwordisokk) is None:
            print("Your password needs a number,please enter one")
            passwordisokk = False
            print(passwordisokk)
        elif re.search("[A-Z]",passwordisokk) is None:
            print(" Your password needs a capital letter,please enter one")
            passwordisokk = False
            print(passwordisokk)
        elif re.search("[$,#,%,&,*]",passwordisokk) is None:
            print(" You password needs one of these symbols:$,#,%,&,*. Please enter one")
            passwordisokk = False
            print(passwordisokk)
        elif re.search("[ ]",passwordisokk):
            passwordisokk = False
            print("No spaces when entering your password please")
            print(passwordisokk)
        else:
            passwordisokk = True
            print(passwordisokk)
            break
passwordisOK()
python python-module
1个回答
3
投票

只需将elifelse更改为if语句。

import re

passwordisokk = True

def checkPasswordisOK():
    while True:
        password = input("Please enter a password so we can validate:")
        if len(password) < 10:
            print(" Your password should be 10 characters,please enter more characters")
            passwordisokk = False
            print(passwordisokk)
        if re.search("[0-9]",password) is None:
            print("Your password needs a number,please enter one")
            passwordisokk = False
            print(passwordisokk)
        if re.search("[A-Z]",password) is None:
            print(" Your password needs a capital letter,please enter one")
            passwordisokk = False
            print(passwordisokk)
        if re.search("[$,#,%,&,*]",password) is None:
            print(" You password needs one of these symbols:$,#,%,&,*. Please enter one")
            passwordisokk = False
            print(passwordisokk)
        if re.search("[ ]",password):
            passwordisokk = False
            print("No spaces when entering your password please")
            print(passwordisokk)
        if not passwordisokk:
            passwordisokk = True
            print(passwordisokk)
            break
checkPasswordisOK()
© www.soinside.com 2019 - 2024. All rights reserved.