Defensive design considerations: Anticipating misuse, Authentication
2.3.1 Defensive Design
Practise exam questionsDefensive Design — Note 1 of 3
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.
Exam tipCommon mistake
Verifying a user's identity, typically through a username and password.
# 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")Ready to test yourself?
Practise 2.3.1 questions