Password Validator

Validate password strength.

BeginnerPhase 6 - Category 5: Real-World Logic ProblemsExample 13 of 15
password-validator.py
1# Take password
2password = input("Enter password: ")
3
4# Validate
5has_upper = any(c.isupper() for c in password)
6has_lower = any(c.islower() for c in password)
7has_digit = any(c.isdigit() for c in password)
8has_special = any(c in "!@#$%^&*" for c in password)
9length_ok = len(password) >= 8
10
11if length_ok and has_upper and has_lower and has_digit and has_special:
12 print("Strong password")
13elif length_ok and (has_upper or has_lower) and has_digit:
14 print("Medium password")
15else:
16 print("Weak password")

Output

Enter password: MyPass123!
Strong password

What's going on

Check multiple conditions.

Key Concepts:

Check various character types
Validate length
Classify strength