From e31bddea19a4993f10b5c505ee9a54ff991a23ca Mon Sep 17 00:00:00 2001 From: url Date: Sun, 19 Jul 2026 16:14:48 +0100 Subject: [PATCH] add password checker - lesson 01 --- .../01-password-checker/password_checker.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 learning/01-password-checker/password_checker.py diff --git a/learning/01-password-checker/password_checker.py b/learning/01-password-checker/password_checker.py new file mode 100644 index 0000000..606271e --- /dev/null +++ b/learning/01-password-checker/password_checker.py @@ -0,0 +1,21 @@ +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)}") \ No newline at end of file