Answer to Question #303400 in Python for divya

Question #303400

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:05:25-0500
def isValidPassword(password):
    lower = 'qwertyuiopasdfghjklzxcvbnm'
    upper = 'QWERTYUIOPASDFGHJKLZXCVBNM'
    digits = '0123456789'
    special = '~!@#$%^&*_+-=<>? '
    l = False
    u = False
    d = 0
    s = 0
    len = 0
    for char in password:
        if char in lower:
            l = True
        if char in upper:
            u = True
        if char in digits:
            d += 1
        if char in special:
            s += 1
        len += 1
    if len>=10 and l and u and d>=3 and s>=2:
        return True
    else:
        return False

print(isValidPassword('ASDFG123@ '))
print(isValidPassword('asdfg123@!'))
print(isValidPassword('ASDfg12j@!'))
print(isValidPassword('ASDf!123@'))
print(isValidPassword('ASDfg123@!'))

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