Answer to Question #303633 in Python for dip

Question #303633

Define a function named "isValidPassword" which take a string as parameter. The function will then check if the supplied string fulfilled the following password criterias: 1) must have combination of uppercase and lowercase 2) must have at least 3 digits 3) must have at least 2 special character (including whitespace). 4) must have at least 10 characters (combination of alphanumeric and special symbol) The function will return a Boolean value i.e. True if all criterias are met or return False otherwise. Make sure you test your function with every single possible input that may return False value as well.


1
Expert's answer
2022-02-28T01:08:00-0500
def isValidPassword(password):
    sym = 0
    num = 0
    upper = False
    lower = False
    if len(password) >= 10:
        for s in password:
            if s.isalpha():
                if s.islower():
                    lower = True
                else:
                    upper = True
            elif s.isdigit():
                num += 1
            else:
                sym += 1

    if upper and lower and num >= 3 and sym >= 2:
        return True
    else:
        return False

print(isValidPassword("Hello123&%")) #True

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS