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.
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 deniedif the pair is not valid; - display
Access grantedif 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 grantedandAccess denieddisplayed 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 == Yusuf5compares 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 deniedafter the loop. It must be shown on every failed attempt, so it is inside.- A
forloop 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.
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)
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
- Question 6: Essay marks with penalties for late essays, never below 0 7 marks
- Question 7: Build a stock code with string indexing and concatenation 4 marks
- Question 12.6, 12.7: Use given subroutines to check a row and to play until solved 10 marks
- Question 14: Local variables, and a subroutine that counts busy days and returns the count 7 marks
- Question 15: Move 1 or 2 along a row of cells, back to 0 on an X or past the end 8 marks
Every AQA 8525 question we have worked
Learn it step by step
- F6.2 Authentication Robust programs
- F2.6 Condition-controlled loops: while Decisions and loops
- F13.4 Programming questions Exam preparation
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.