AQA GCSE Computer Science June 2024 Paper 1, Question 11: the authentication program

AQA 8525 June 2024 Paper 1, Question 11: write a Python program that checks a username and password against two valid pairs, displays Access denied or Access granted, and repeats until a valid pair is entered. A model answer, the brackets that matter, and the program to run.

Past paper questionAQA 8525/1BJune 2024 Paper 17 marksWrite a program

Question 11 of the AQA GCSE Computer Science Paper 1 sat on 15 May 2024 (8525/1B, the Python paper) is a 7 mark "write a program" question. The loop is ordinary. The Boolean condition is where the marks are: two valid pairs, which must not get mixed.

We do not copy the exam paper here. Open it beside this page: AQA June 2024 Paper 1B question paper (PDF). When you have finished, check the mark scheme too.

The question in short

There are two valid users: Yusuf5 with the password 33kk, and Mary80 with the password af5r. The program should:

  • get a username and a password from the user;
  • display Access denied if the pair is not valid;
  • display Access granted if it is;
  • repeat until a valid pair is entered.

A model answer

access = False
while access == False:
    username = input("Username: ")
    password = input("Password: ")
    if (username == "Yusuf5" and password == "33kk") or (username == "Mary80" and password == "af5r"):
        print("Access granted")
        access = True
    else:
        print("Access denied")

The brackets matter

Each pair is one bracketed and. The two pairs are joined with or. That keeps Yusuf's password with Yusuf.

Compare it with this, which looks similar and is wrong:

(username == "Yusuf5" or username == "Mary80") and (password == "33kk" or password == "af5r")

That lets Yusuf5 in with Mary's password.

Where the seven marks are

Two marks are for design: meaningful variable names, and an indefinite loop (a while).

Five marks are for a program that works:

  • the username and password input and stored in two variables;
  • a correct check of at least one valid pair;
  • a correct check of both valid pairs;
  • asking for the username and password again in the right place;
  • Access granted and Access denied displayed in the right places.

Any error caps you at 6. The mark scheme allows missing quotation marks for the fourth of those marks only. For the fifth, every string needs its quotes.

Where the marks are lost

  • Mixing the pairs. See above.
  • No quotation marks. username == Yusuf5 compares with a variable that does not exist.
  • Inputs before the loop only. Then a wrong pair can never be corrected, and the loop runs for ever.
  • Access denied after the loop. It must be shown on every failed attempt, so it is inside.
  • A for loop with three tries. The question says repeat until a valid pair is entered.

Run it

The program, guarding the robot. The light is red while you are locked out. When you get in, it goes green and the robot drives.

Try Yusuf5 with af5r: denied, because the pairs are not mixed. Then Mary80 with af5r: granted.
The program
from bugbot import *
connect()

access = False
led("red")
while access == False:
    username = input("Username: ")
    password = input("Password: ")
    if (username == "Yusuf5" and password == "33kk") or (username == "Mary80" and password == "af5r"):
        print("Access granted")
        access = True
    else:
        print("Access denied")
led("green")
forward(60, distance=20)
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What is the answer to AQA GCSE Computer Science 2024 Paper 1 Question 11?

Loop while access has not been granted. Inside, input the username and password. If they match the first pair or the second pair, display Access granted and end the loop. Otherwise display Access denied.

How do I check two valid username and password pairs?

Test each pair with AND inside brackets, and join the two brackets with OR: (user is A and password is X) or (user is B and password is Y).

What is authentication?

Confirming that a user is who they claim to be, usually by checking a username and password against stored values before giving access.

More from this paper

Every AQA 8525 question we have worked

Learn it step by step

  1. F6.2 Authentication Robust programs
  2. F2.6 Condition-controlled loops: while Decisions and loops
  3. F13.4 Programming questions Exam preparation
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by AQA, and the question paper and mark scheme remain AQA's copyright. Read them on AQA's site with the links on this page.