Previous Module
Next Module

COMPUTER SYSTEMS: Encoding and compression

COMPUTER SYSTEMS: Network topologies

COMPUTER SYSTEMS: Wired and wireless networks, protocols, and layers

COMPUTER SYSTEMS: Threats to computer systems and networks

COMPUTER SYSTEMS: Operating systems and utility software

ALGORITHMS AND PROGRAMMING: Types of data

ALGORITHMS AND PROGRAMMING: Producing robust programs

ALGORITHMS AND PROGRAMMING: Designing, creating, and refining algorithms

ALGORITHMS AND PROGRAMMING: Artificial Intelligence (AI)

  • Defensive design is about writing programs that can anticipate problems before they happen – especially incorrect inputs or misuse.
  • Anticipating misuse: users might enter invalid, unexpected, or malicious input. The program should handle this without crashing. 
    • Examples of misuse include typing letters into a number input, leaving fields blank, and entering a script or code (e.g. for hacking)
    • This can be addressed by using input validation, using authentication (to check who the user is), or displaying error messages and ask for correct input
  • Authentication: is used to verify a user’s identity, typically using:
    • Username + Password
    • Sometimes 2FA (two-factor authentication)
  • Input validation: checks that the user’s input is acceptable before using it in the program. Validation prevents bugs and improves security.
Common types of checks What it does Example
Length Checks input is not too short or long Password length > = 8
Range Ensures number is within limits Age between 0 and 120
Type Checks if input is the right type Number not string
Format Pattern is correct Email contains @
Presence Ensures input is not empty Name is not blank

# Authentication example

username = input(“Enter username:”)

password = input(“Enter password:”)

 
 

if username == “admin

and password == “1234

print(“Access granted”)

else:

print(“Access denied”)

# Age validation example

age = input(“Enter your age:”)

 
 

if age.isdigit():

age = int(age)

if age > = 0 and age < = 120:

print(“Valid age”)

else:

print(“Age out of range”)

else:

print(“Please enter a number”)

Unlock Defensive design

Subscribe to SnapRevise+ to get immediate access to the rest of this resource.

Premium accounts get immediate access to this resource.

Previous Module
Next Module