GCSE · Computer Science · AQA · Spec 8525
Authentication routines
Every login you have ever typed was judged by a handful of ordinary lines of code. Right username, wrong password? Let's find the exact line that keeps you out.
Computer Science · Robust programs
Watch a login refuse three attempts
Step through the code one line at a time. The variables on the right show exactly what the program knows at each moment.
Attempt 1 has the right username. Predict before you step: does the program let them in?
1 storedUser ← "kai07"2 storedPass ← "tulip9"3 attempts ← 04 loggedIn ← False5 WHILE loggedIn = False AND attempts < 36 username ← INPUT7 password ← INPUT8 IF username = storedUser AND password = storedPass THEN9 loggedIn ← True10 OUTPUT "Welcome!"11 ELSE12 attempts ← attempts + 113 OUTPUT "Username or password not recognised"14 ENDIF15 ENDWHILE16 IF loggedIn = False THEN17 OUTPUT "Too many attempts. Locked out."18 ENDIF
Variables
Output
Step 1: Set-up. The program already holds the right details: the stored values kai07 and tulip9. Nobody has tried yet, so attempts is 0 and loggedIn is False.
Press Next to move one line at a time. At every IF, decide TRUE or FALSE yourself before you read the note.
Computer Science · Boolean logic
Four ways to try, one way in
Walk all four routes. Before you start, guess: how many of them end with access granted?
Username check → Password check
4 possible results of one login attempt.
Every attempt is checked twice: the username, then the password. Walk each route and see where it ends.
Computer Science · Algorithms
Trace table — dry run the code
Kai types the username kai07 and the password m00n. m00n is a real password, it just isn't Kai's. Predict: in or out?
Ready when you are — step through one line at a time.
Computer Science · Robust programs
Sensible data, or the right person?
Is each check validation or authentication? Commit first, then read why.
Still to sort
Validation (0)
Checks the input is sensible or follows a rule.
Where the line is: Anyone can type data that passes validation. It says nothing about who they are.
Authentication (0)
Checks the user is who they claim to be.
Where the line is: Needs the user's details to match what is stored for them.
Programs make lots of checks. Sort each one, then read why it goes there.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- Authentication confirms a user is who they claim to be before the program lets them continue or access data.
- A simple routine inputs a username and a password, then compares both with the stored (expected) values.
- In the IF, = compares two strings exactly, character by character, and gives TRUE or FALSE.
- AND joins the two checks: access only when both match. If either fails, access is refused and a message is output.
Have a goYour mate Jas grins: "I know the username, so I'm already halfway in." With AND joining the two checks, how far in is Jas?
Not in at all. Jas is refused, with a message.
AND needs both checks TRUE. One match counts for nothing, so Jas is treated exactly like someone who got both details wrong.
- A WHILE or REPEAT loop asks the user again after a failed attempt.
- A counter adds 1 for each failure; when it reaches the limit, the loop stops and the user is locked out.
Have a goThe limit is 3, the counter starts at 0 and adds 1 per failure. You have just failed twice. How many goes do you have left?
One.
The counter is at 2. One more failure takes it to 3, the limit, and you are locked out. It is tempting to think the limit of 3 means 3 more goes.
- Credentials can sit in variables, or in lists where each password is at the same position as its username.
- Validation checks data is sensible, like a length or range check; authentication checks who the user is.
Have a goA sign-up form will not submit until the new password has at least 8 characters. Is that validation or authentication?
Validation: a length check.
It checks the input follows a rule, not that it matches anything stored. A total stranger could type 8 characters and pass, so it proves nothing about who they are.
- Authentication helps keep a program secure by stopping unauthorised users getting into it or its data.
The big picture
An authentication routine checks that a user is who they claim to be before letting them into a program or its data. It inputs a username and a password, compares each with the stored value, and uses AND inside an IF so access is granted only when both match. A loop gives the user another go after a failure, and a counter locks them out once the limit is reached. That is a different job from validation, which only checks that data is sensible.
Key points
Worked example
Problem
Use the login routine from the top of the page (stored details kai07 and tulip9, a limit of 3 attempts). A user types kia07 and tulip9, then kai07 and tulip9. What does the program output, and what are attempts and loggedIn when it finishes?
⚠ Watch out
Thinking a correct username gets you halfway in. It feels like progress, but with AND one match counts for nothing: TRUE AND FALSE is FALSE, so the user is refused exactly as if both details were wrong.
Memory hook
Both or nothing, and count the fails. Username AND password must match, and the counter says when the tries run out.
Check yourself
Stored details: ada and lamp22, with 3 attempts allowed. A user types ada and Lamp22 on their first go. Are they let in, and what happens to attempts?
Flashcards
(13)What is authentication?
What two inputs does a simple authentication routine ask for?
What are the entered username and password compared with?
In IF password = storedPass, what does = do?
Are Tulip9 and tulip9 equal strings?
Why is AND used to combine the username and password checks?
What would go wrong if OR joined the two checks?
Which construct decides whether to grant or refuse access?
Which construct lets the user try again after a failed attempt?
What does the attempts counter do?
Credentials are stored in two lists. Which password is checked for the username typed?
What does validation check?
Why do programs use authentication routines?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 28 October 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.