Question bank › GCSE › GCSE Computer Science › Programming

Data validation & authentication routines

10 questions45 marksabout 55 min

Answer on paper first, then reveal the mark scheme one mark at a time.

1Grade 1–33 marks

State the type of validation check being described in each case. [3]

(a) An exam mark entered must be between 0 and 100.
(b) The username field must not be left empty.
(c) A password must contain at least 8 characters.

2Grade 6–75 marks

A program asks the user how many concert tickets they want to buy. The number must be between 1 and 6 inclusive.

Write an algorithm, using pseudo-code or program code, that keeps asking the user to enter the number of tickets until a valid number is entered, displaying an error message each time an invalid number is entered. You may assume the user always enters an integer. [5]

3Grade 6–75 marks

This algorithm is an authentication routine.

attempts ← 0
REPEAT
   OUTPUT 'Enter password'
   pw ← USERINPUT
   attempts ← attempts + 1
UNTIL pw = 'Tr0ub4dor' OR attempts = 3
IF pw = 'Tr0ub4dor' THEN
   OUTPUT 'Access granted'
ELSE
   OUTPUT 'Locked'
ENDIF

(a) The user enters abc then Tr0ub4dor. State the final value of attempts and the final output. [2]

(b) State the final output if the user enters red, blue and then green. [1]

(c) Explain how limiting the number of attempts makes the system more secure. [1]

(d) Suggest one other way the authentication could be made more secure. [1]

Stuck on Data validation & authentication routines?

Get it sorted in a free 30-minute session

We work through your weakest questions on this topic on Zoom. I reply the same day.

4Grade 1–33 marks

A gaming website checks the nickname a new player types in.

OUTPUT 'Enter nickname'
nick ← USERINPUT
IF LEN(nick) < 3 OR LEN(nick) > 12 THEN
   OUTPUT 'Nickname rejected'
ELSE
   OUTPUT 'Welcome ' + nick
ENDIF

(a) State the output when the player enters Al. [1]

(b) State the output when the player enters Sam. [1]

(c) State the type of validation check that this routine performs. [1]

5Grade 1–34 marks

A weather station program stores a temperature reading, temp, typed in by a volunteer. Readings must be between −10 and 40 inclusive. This validation routine is used:

IF temp ≥ -10 AND temp ≤ 40 THEN
   OUTPUT 'Accepted'
ELSE
   OUTPUT 'Rejected'
ENDIF

(a) Complete the table to show the output for each test value. [3]

Test value of tempOutput
−11 
−10 
23 

(b) State one other value of temp that should be used to test the upper boundary of the range, and give its expected output. [1]

6Grade 4–54 marks

A library self-service kiosk uses both validation and authentication routines.

(a) Describe what is meant by validation. [1]

(b) Describe what is meant by authentication. [1]

(c) A member types their date of birth into the kiosk. The kiosk checks that the year entered is between 1900 and the current year. Explain why the date of birth could still be wrong even though it passes this check. [2]

7Grade 4–54 marks

A youth club app only allows members aged 13 to 19 inclusive to sign up. A programmer writes this routine.

age ← STRING_TO_INT(USERINPUT)
IF age > 13 AND age ≤ 19 THEN
   OUTPUT 'Welcome'
ELSE
   OUTPUT 'Not eligible'
ENDIF

The routine contains an error.

(a) State a value of age that shows the error, and give the output the routine produces for that value and the output it should produce. [2]

(b) Rewrite the IF line so that the routine works correctly. [1]

(c) State the type of error in the original routine. [1]

8Grade 6–75 marks

A banking app checks that a PIN typed by a user is made up of exactly four digits.

pin ← '12a4'
valid ← True
IF LEN(pin) ≠ 4 THEN
   valid ← False
ENDIF
FOR i ← 0 TO LEN(pin) - 1
   c ← SUBSTRING(i, i, pin)
   IF c < '0' OR c > '9' THEN
      valid ← False
   ENDIF
ENDFOR
OUTPUT valid

(a) Complete the trace table for the algorithm. The first row shows the values before the loop starts. [3]

icvalid
  True
0  
   
   
   

(b) State the final output of the algorithm. [1]

(c) State the output if the first line were changed to pin ← '0427'. [1]

9Grade 8–96 marks

A school printing system stores registered usernames and their passwords in two arrays. The password for each user is stored at the same index as their username.

users ← ['amir', 'bella', 'chen']
pwds ← ['kite42', 'sun7', 'ox99']

Write an algorithm, using pseudo-code or program code, that:

  • asks the user to enter a username and a password
  • searches the users array for the username entered
  • outputs Logged in if the username is found and the password entered matches the password stored at the same index
  • otherwise outputs Login failed exactly once.

The arrays may be of any length. [6]

10Grade 6–76 marks

A review website lets customers leave a comment. A comment is only accepted if it is not empty and is no longer than 200 characters.

(a) Write a subroutine called validComment that takes a string parameter text and returns True if the comment is accepted and False otherwise. [4]

(b) Give two items of boundary test data for the subroutine. For each one, state the value that should be returned. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session