TopMyGrade

GCSE/Computer Science/AQA

CS2.11Robust and secure programming: validation, authentication, defensive programming, anticipating misuse and edge cases

Notes

Robust and secure programming

Robust software works correctly not just for expected inputs but also for unexpected, missing or malicious ones. Secure software protects against deliberate attacks. AQA GCSE focuses on four strategies: validation, authentication, defensive programming and anticipating misuse.

Validation

Validation checks that data is reasonable and in the correct format before processing it. It does NOT check whether the data is true — it can't know if "John Smith" is a real person.

Common validation checks:

CheckPurposeExample
Range checkValue within acceptable limitsAge between 0 and 120
Type checkCorrect data typePostcode must be a string
Length checkNot too short/longPassword 8–20 characters
Presence checkField not emptyUsername cannot be blank
Format checkMatches a patternEmail must contain @
Lookup checkValue in permitted setCountry code in approved list

AQA pseudocode — range-checked age entry:

REPEAT
  OUTPUT "Enter your age (1-120): "
  USERINPUT age
UNTIL age >= 1 AND age <= 120

Authentication

Authentication confirms that a user is who they claim to be. This is separate from authorisation (what an authenticated user is allowed to do).

Common authentication methods:

  • Username and password — most common; vulnerable if passwords are weak or reused
  • PIN — short numeric code; fast but less secure
  • Biometrics — fingerprint, face recognition; difficult to fake but raises privacy concerns
  • Two-factor authentication (2FA) — combines two of: something you know (password), something you have (phone/token), something you are (biometric)
  • CAPTCHA — confirms the user is human, not an automated bot

Good password practices:

  • Minimum length (e.g., 8+ characters)
  • Mix of upper/lowercase, digits and symbols
  • Never stored as plaintext — always hashed
  • Account lockout after repeated failed attempts

Defensive programming

Defensive programming means writing code that anticipates problems and handles them gracefully, rather than crashing or producing wrong results.

Techniques include:

  1. Input validation (see above) — reject bad data early
  2. Error handling — use try/except (or equivalent) to catch runtime errors
  3. Meaningful error messages — tell the user what went wrong and how to fix it
  4. Sensible defaults — provide fallback values when input is missing
  5. Code commenting — so future programmers (including yourself) understand the logic

AQA pseudocode — defensive integer input:

SUBROUTINE getPositiveInt(prompt)
  REPEAT
    OUTPUT prompt
    USERINPUT value
  UNTIL value > 0 AND value = INT(value)
  RETURN value
ENDSUBROUTINE

Anticipating misuse and edge cases

Edge cases are inputs at the boundary of what is valid (e.g., exactly 0, or the maximum allowed value). Misuse includes:

  • Entering letters into a numeric field
  • Deliberately entering SQL injection strings
  • Uploading oversized files
  • Leaving required fields blank
  • Clicking "Submit" multiple times

A good programmer tests with:

  • Normal data — typical, expected input
  • Boundary data — at the edge of valid range (just inside and just outside)
  • Erroneous data — completely wrong type or format

Why it matters

A program that crashes on unexpected input is unreliable. A program with no authentication lets anyone access private data. Robust, secure programs build user trust and reduce support burden.

AI-generated · claude-opus-4-7 · v3-deep-computer-science

Practice questions

Try each before peeking at the worked solution.

  1. Question 14 marks

    Types of validation

    A form asks for a student's age (must be between 11 and 18). Identify two appropriate validation checks and explain each.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  2. Question 24 marks

    Validation vs verification

    Explain the difference between validation and verification, using an example of each.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  3. Question 33 marks

    Authentication methods

    A banking app uses a password plus a one-time code sent to the user's phone. (a) What is this type of authentication called? (b) Explain one advantage over password-only login.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  4. Question 45 marks

    Defensive programming loop

    Write pseudocode for a subroutine called getScore() that repeatedly asks for an integer between 0 and 100 until a valid value is entered, then returns it.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  5. Question 56 marks

    Edge case testing

    A program accepts a score between 0 and 100 inclusive. State three test data values you would use — one normal, one boundary and one erroneous — and explain why each is useful.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  6. Question 63 marks

    Password security

    Give three features of a secure password policy for a website.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

Flashcards

CS2.11 — Robust and secure programming

12-card SR deck for AQA GCSE Computer Science topic CS2.11

12 cards · spaced repetition (SM-2)