Files
ou-python/learning/01-password-checker/password_checker.py
T
2026-07-19 16:14:48 +01:00

21 lines
658 B
Python

import random
import getpass
def check_password(user_input, correct_password):
return user_input == correct_password
failure_messages = [
"CIA farm boys alerted",
"NSA coordinating with NORAD",
"UNSC notified of impending domestic launch",
"Thermonuclear war initiated",
"Rerouting through the Pentagon",
]
max_attempts = 5
attempts = 0
while attempts < max_attempts:
user_input = getpass.getpass("Enter password: ")
if check_password(user_input, "joshua"):
print("Access granted!")
break
else:
attempts += 1
print(f"Attempt {attempts} of {max_attempts}: {random.choice(failure_messages)}")