Knowledge organisersDefensive Design
Understanding of the issues a programmer should consider to ensure that a program caters for all likely input values; Understanding of how to deal with invalid data in a program; Authentication to confirm the identity of a user
Defensive design means writing programs that can handle unexpected or incorrect inputs by anticipating how users might misuse the program. Authentication is the process of verifying a user's identity, typically through a username and password. Good defensive design reduces bugs and ensures the program behaves correctly regardless of what the user enters.
# Simple username and password authentication
stored_user = "admin"
stored_pass = "secret123"
username = input("Username: ")
password = input("Password: ")
if username == stored_user and password == stored_pass:
print("Access granted")
else:
print("Access denied")