Loading lessons...
Project 10: Password Checker
Project 10: Password Checker
Check that a password is strong: at least 8 characters, with a number and a capital letter.
The goal
Ask for a password and report whether it passes each rule, printing helpful feedback.
What you practice
- len() and string methods
- Loops
- any() and all()
- Functions
Starter code
def check_length(pw):
return len(pw) >= 8
def has_number(pw):
return any(ch.isdigit() for ch in pw)
def has_capital(pw):
return any(ch.isupper() for ch in pw)
password = input("Create a password: ")
print("Length ok:", check_length(password))
print("Has number:", has_number(password))
print("Has capital:", has_capital(password))
Step-by-step
- Run the starter and test a few passwords.
- Add a rule that requires at least one lowercase letter.
- Combine all rules into one
is_strong()function. - Print a clear message: strong or which rule is missing.
- Loop until the user creates a strong password.
Checklist
- [ ] Length rule works
- [ ] Number rule works
- [ ] Capital rule works
- [ ] all() combines the rules
- [ ] Feedback is clear
- [ ] The program loops until success
TL;DR
- isdigit() and isupper() test characters.
- any() is True if any check passes.
- all() is True only when every check passes.