diff --git a/.gitignore b/.gitignore index bee8a64..1efb85e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +.appmodconfig diff --git a/Programs/login.py b/Programs/login.py new file mode 100644 index 0000000..d4f5233 --- /dev/null +++ b/Programs/login.py @@ -0,0 +1,32 @@ +class LoginSystem: + def __init__(self): + self.valid_email = os.getenv("VALID_EMAIL") + self.valid_password = os.getenv("VALID_PASSWORD") + self.failed_attempts = 0 + self.locked = False + + def login(self, email, password): + if self.locked: + return "Account is locked. Contact support." + + if email == self.valid_email and password == self.valid_password: + self.failed_attempts = 0 + return "Login Successful ✅" + + else: + self.failed_attempts += 1 + + if self.failed_attempts >= 3: + self.locked = True + return "Account locked due to 3 failed attempts ❌" + + return f"Invalid credentials. Attempts left: {3 - self.failed_attempts}" + +# ----- Testing the function ----- + +app = LoginSystem() + +print(app.login("wrong@test.com", "123")) # Test case 1 +print(app.login("wrong@test.com", "123")) # Test case 2 +print(app.login("wrong@test.com", "123")) # Test case 3 (locks account) +print(app.login("user@test.com", "Password@123")) # Should fail because account is locked