Defense Points 0 / 27
Defense Rank Bug Generator

2.3

Defensive Design & Testing

Question 1 [5 Marks]
(a) A web form allows users to enter their username. A hacker attempts to enter the following input:
Admin; DROP TABLE Users;

(i) Identify the name of the specific threat the hacker is attempting.
[1]

(ii) Explain how Input Sanitisation would prevent this threat from being successful.
[2]

(b) Define the difference between Validation and Verification.
[2]
✅ Mark Scheme

1ai: SQL Injection

1aii: Sanitisation removes/strips dangerous characters (like ; or ') (1) so the input is treated as text/string rather than a command (1).

1b: Validation: Checking data is sensible/reasonable/meets criteria (1).
Verification: Checking data matches the original source / is copied correctly (1).

Score:
Question 2 [5 Marks]
A program is written to grade students based on their percentage score (0 to 100).
  • Scores under 40 are a "Fail".
  • Scores 40 and above are a "Pass".
The following test plan is created. Complete the table.
[5]
Test Type Test Data Reason for Test Expected Outcome
Normal 65 To check that a typical passing score is accepted. Output "Pass"
Boundary 39 (a) .................................................... (b) .........................
Boundary (c) ........... To check the lowest score required to Pass. Output "Pass"
Erroneous 101 (d) .................................................... (e) .........................
✅ Mark Scheme

2: (a) To check the highest value that results in a Fail (1).
(b) Output "Fail" (1).
(c) 40 (1).
(d) To check that data outside the valid range (upper limit) is rejected (1).
(e) Error message displayed / Asks for input again (1).

Score:
Question 3 [4 Marks]
A programmer has written a function to validate a new password. The rules are:
  • Password must be at least 8 characters long.
  • Password must not be empty.
The code contains one Syntax Error and one Logic Error.
01 def validate_password(pWord): 02 if len(pWord) == 0: 03 print("Error: Password cannot be empty") 04 return False 05 elif len(pWord) < 8 06 print("Error: Password too short") 07 return True 08 else: 09 return True
(a) Identify the line number of the Syntax Error and write the corrected line.
[2]
Line Number: .............
Correction: ............................................................................................

(b) Identify the line number of the Logic Error and explain why it is an error.
[2]
Line Number: .............
Explanation: ...........................................................................................
✅ Mark Scheme

3a: Line 05 (1).
Correction: elif len(pWord) < 8: (1)

3b: Line 07 (1).
Explanation: It returns True when the password is too short / it should return False (1).

Score:
Question 4 [6 Marks]
Write an algorithm using Python or Exam Reference Language for a secure login system.
The system must:
  • Ask the user for a password.
  • Check if the input matches the stored password "Secret123".
  • Allow the user 3 attempts maximum.
  • If the password is correct, output "Access Granted" and stop.
  • If the password is wrong 3 times, output "Account Locked".
[6]
✅ Mark Scheme

4: attempts = 0
auth = False
while attempts < 3 and auth == False:
  pwd = input("Enter password: ")
  if pwd == "Secret123":
    print("Access Granted")
    auth = True
  else: attempts = attempts + 1
if auth == False: print("Account Locked")

Score:
Question 5 [6 Marks]
(a) Describe two ways (other than comments) to make the code in Question 4 maintainable.
[4]
1. ..................................................................................................... 2. .....................................................................................................
(b) Identify the names of these two types of testing described below.
[2]
Testing while writing code to ensure logic/loops work:
.........................................................................................................

Testing the entire system against requirements before release:
.........................................................................................................
✅ Mark Scheme

5a: 1. Indentation: Shows the structure/hierarchy of the code (2).
2. Meaningful Variable Names: Using attempts instead of x (2).
(Alternative: Subprograms/Modules).

5b: 1. Iterative Testing (1).
2. Final / Terminal Testing (1).

Score:
Question 6 [4 Marks]
Consider the following Python code intended to divide two numbers.
num1 = int(input("Enter number 1: ")) num2 = int(input("Enter number 2: ")) print(num1 / num2)
(a) If the user enters 10 for num1 and 0 for num2, the program crashes. State the name of this type of error.
[1]

(b) Rewrite the code using a defensive design technique (selection) to prevent this crash.
[3]
✅ Mark Scheme

6a: Runtime Error / Execution Error

6b: if num2 == 0:
  print("Cannot divide by zero")
else: print(num1 / num2)

Score: