简体   繁体   中英

python - password checker function always returning weak password

I've got a function in my script which gets an argument and compares it to some set variables to see whether the password is of suitable strength or not. Whenever I enter a password both suitable/unsuitable, it returns that the password is too weak. Code below:

def check_password(_passw):

    length = len(_passw) < 8
    num = re.search(r'\d', _passw) is None
    uppercase = re.search(r"[A-Z]", _passw) is None
    lowercase = re.search(r"[a-z]", _passw) is None

    suitable = not (length or num or uppercase or lowercase)

    if _passw is not suitable:
        print('Password weak, try again')
        sign_up()

    else:
        print('Password accepted')
if _passw is not suitable:

is too colloquial really. You mean

if not suitable:  

edit:
The 'is' operator in python tests if 2 variables point to the same memory location (aka instance). It does not compare the values of these 2 variables. See for instance here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM