Your Fourth Mini Project — Lock It Down
The problem...
You already built a username generator in your first mini project. You have an identity.
Now you need to protect it.
A weak password is an open door. And open doors get walked through.
The idea!
You're going to build a password validator.
The user types a password. Your program checks if it meets the requirements.
No guessing. No maybe. True or False.
The requirements
A valid password must:
- Be at least 8 characters long
- Contain at least one uppercase letter
- Contain at least one number
- Not contain spaces
Four conditions. All must be true. That's and.
Step by step
Get the password:
password = input("Enter your password: ")
long_enough = len(password) >= 8
has_upper = password != password.lower()
has_number = (
"0" in password or "1" in password or "2" in password or
"3" in password or "4" in password or "5" in password or
"6" in password or "7" in password or "8" in password or
"9" in password
)
no_spaces = " " not in password
is_valid = long_enough and has_upper and has_number and no_spaces
print(f"Password valid: {is_valid}")
Combine them:
is_valid = long_enough and has_upper and has_number and no_spaces
print(f"Password valid: {is_valid}")
The full program
password = input("Enter your password: ")
long_enough = len(password) >= 8
has_upper = password != password.lower()
has_number = any(char.isdigit() for char in password)
no_spaces = " " not in password
is_valid = long_enough and has_upper and has_number and no_spaces
print(f"Long enough: {long_enough}")
print(f"Has uppercase: {has_upper}")
print(f"Has number: {has_number}")
print(f"No spaces: {no_spaces}")
print(f"Password valid: {is_valid}")
If the user types RedHorn7:
Long enough: True
Has uppercase: True
Has number: True
No spaces: True
Password valid: True
If the user types redhorndev:
Long enough: True
Has uppercase: False
Has number: False
No spaces: True
Password valid: False
What's really happening
Each condition returns a bool. You store it in a variable. You combine them with and.
The final result is one bool — valid or not. No ambiguity. No maybe.
That's exactly how real authentication systems think.
Heads up!
password != password.lower()— if the password has no uppercase, lowercasing it changes nothing- Each condition is a separate bool — you can print them individually to debug
The mindset shift
Stop thinking: "Validation is complicated."
Start thinking: "Every requirement is just a condition. Every condition is just a bool."
What you should understand now
- Real problems can be broken into bool conditions
andcombines multiple conditions into one answer- Each condition can be stored and printed separately
- True or False — that's all validation ever is