Knowledge organisersDefensive Design
Username + password.
Authentication verifies a user's identity, typically with a username and password. A simple implementation checks entered credentials against stored values.
== for comparison, not =STORED_USER = "admin"
STORED_PASS = "secret123"
attempts = 3
user = input("Username: ")
pwd = input("Password: ")
while (user != STORED_USER or pwd != STORED_PASS) and attempts > 1:
attempts -= 1
print("Incorrect. " + str(attempts) + " attempts left")
user = input("Username: ")
pwd = input("Password: ")
if user == STORED_USER and pwd == STORED_PASS:
print("Login successful")
else:
print("Account locked")