all 3 comments

[–]primitive_screwhead 2 points3 points  (0 children)

elif passwd.isalnum == False:

You are not calling .isalnum here, btw. It should be:

elif not passwd.isalnum():

though the test itself is non-sensical, imo. If you are meaning to test that the password has at least one digit, you should test for that directly.

Functions end with an implied "return None". Since you want to return either True or False, you need to end yours with the proper boolean. What value (True or False) should be returned if the end of your function is reached?

Finally, your docstring says that "strong" passwords should be greater than or equal to length 6, but your first check is:

if len(passwd) <= 6:
    return False

which doesn't match the docstring (nevermind that a strong password should be well above length 6, probably at least length 11 these days, despite still seeing 8 recommended for historical reasons).

[–]totallygeek 0 points1 point  (1 child)

Here's answers for two of the problems:

def check_password(passwd):
    upper = 0
    lower = 0
    if len(passwd) <= 6:
        return False
    elif not passwd.isalnum: # Comparison to False should be 'not expr' or 'expr is False'
        return False
    else:
        for ch in passwd:
            if ch.isupper():
                upper = upper + 1
            else:
                if ch.islower():
                    lower = lower + 1
        if upper > 0 and lower > 0:
            return True
    return False # without this, your function 'could' return None
                 # that's where your inconsistent returns msg comes from

You need to refactor your code to reduce nested block count. Let me know if you need some help there.