Robotics & Artificial Intelligence

Write a function to check the complexity of a password string. A strong password should contain at least 8 characters, including uppercase letters, lowercase letters and digits.

Python String Manipulation

2 Likes

Answer

def check_password_complexity(password):
    if len(password) < 8:
        return "Weak Password"

    has_upper = False
    has_lower = False
    has_digit = False

    for ch in password:
        if ch.isupper():
            has_upper = True
        elif ch.islower():
            has_lower = True
        elif ch.isdigit():
            has_digit = True

    if has_upper and has_lower and has_digit:
        return "Strong Password"
    else:
        return "Weak Password"

password = input("Enter a password: ")
result = check_password_complexity(password)
print(result)

Output

Enter a password: Abc12345
Strong Password

Answered By

1 Like


Related Questions