AQA GCSE Computer Science June 2023 Paper 1, Question 6: completing the login algorithm

AQA 8525 June 2023 Paper 1, Question 6: fill the four gaps in a pseudo-code authentication routine. Each gap explained, where marks are lost, and a working login program for a robot that you can run.

Past paper questionAQA 8525/1BJune 2023 Paper 14 marksComplete the algorithm

Question 6 of the AQA GCSE Computer Science Paper 1 sat on 19 May 2023 (8525/1B, the Python paper) shows a pseudo-code authentication routine with four parts missing, labelled L1 to L4. You pick the missing parts from a grid of twelve options. One mark each, 4 marks in all.

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

The question in short

The routine repeats until the user has logged in.

  1. It keeps asking for a username until one is typed. The thing assigned to username is missing (L1).
  2. It keeps asking for a password until one is typed.
  3. It calls a subroutine, getPassword, to look up the stored password. The subroutine returns the password for that user, or an empty string if there is no such user. What is passed to it is missing (L2).
  4. It compares the stored password with something (L3) and, if they match, outputs a message (L4).
  5. Otherwise it compares the typed password with the stored one. A match logs the user in. No match outputs "Try again."

Work it through

L1 is USERINPUT. Look two lines further down the paper: the password is read with password ← USERINPUT. The username is read the same way. The options include username and OUTPUT, and neither gets anything from the keyboard.

L2 is username. The subroutine looks a user up, so it needs to know which user. Passing password would make no sense: the password is what you are trying to find.

L3 is '', the empty string. Read the description of getPassword again. It returns an empty string when the user does not exist. So this IF is asking "was the user not found?"

L4 is User not found. This follows from L3. The branch is the one where the username does not exist, so that is what to tell the user. Wrong password is in the grid to tempt you, but the wrong password case is handled further down, by "Try again."

The answers

Label Answer
L1 USERINPUT
L2 username
L3 ''
L4 User not found

Where the marks are lost

  • L3 written with double quotes. The grid shows the empty string as two single quotes. The mark scheme rejects "", because it is not one of the options. Copy the option exactly.
  • Wrong password for L4. Work out what each branch means before you choose a message. The outer IF is about the user. The inner IF is about the password.
  • Reading the code and not the description. Two of the four answers come from the sentences above the code, which say what getPassword takes and returns. Read them first.

Spelling and capital letters do not matter, so long as it is clear which option you chose.

Run it

This is the same routine in Python, guarding a robot. The light goes red for a user that does not exist, yellow for a wrong password and green when you are in. The stored users are ada (password lovelace) and alan (password turing).

Try a user that does not exist, then ada with the wrong password, then ada with lovelace. Only then does the robot drive.
The program
from bugbot import *
connect()

USERS = {"ada": "lovelace", "alan": "turing"}

def get_password(username):
    # the stored password, or an empty string if there is no such user
    if username in USERS:
        return USERS[username]
    return ""

login = False
while login == False:
    username = ""
    while username == "":
        username = input("Enter username: ")           # L1
    password = ""
    while password == "":
        password = input("Enter password: ")
    stored_password = get_password(username)           # L2
    if stored_password == "":                          # L3
        led("red")
        print("User not found")                        # L4
    else:
        if password == stored_password:
            login = True
        else:
            led("yellow")
            print("Try again.")

led("green")
print("You are now logged in.")
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.

Now change it

A real login does not let you guess for ever. Add a variable that counts the failed attempts and stop the program after three. Where does the count go up: for a wrong password, a wrong username, or both?

Questions

What are the answers to AQA GCSE Computer Science 2023 Paper 1 Question 6?

L1 is USERINPUT, L2 is username, L3 is the empty string written as two single quotes, and L4 is User not found.

What is authentication in GCSE Computer Science?

Authentication is checking that a user is who they say they are, usually with a username and a password. It is one of the ways a program is made secure, and AQA expects you to be able to read and write a simple authentication routine.

Why does the routine check for an empty string?

The subroutine that looks up the password returns an empty string when the username does not exist. Testing for the empty string is how the main routine tells "no such user" apart from "wrong password".

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
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.