Paper 2 scenario practice
Password validation with three criteria
The scenario
A website signup form needs to validate passwords. The developer wants a program that:
1. INPUTS a password (a STRING).
2. Checks THREE criteria:
- The password must have a LENGTH of at least 8 characters.
- The password must contain at least ONE DIGIT (a character between '0' and '9').
- The password must contain at least ONE UPPERCASE letter (a character between 'A' and 'Z').
3. Outputs whether the password is VALID (passes all three) or INVALID. If invalid, outputs WHICH criteria failed — so the user knows what to fix.
Use Cambridge string functions: LENGTH(string) returns the number of characters; MID(string, start, length) returns a substring (first character is at position 1).
Write a program in pseudocode (or a high-level language of your choice). Marks will be awarded for correct string-function usage, three independent criteria checks, and clear feedback to the user.
Marking scheme — total 15 marks
Cambridge IGCSE 0478 Paper 2
- 2Read input and declare flags: INPUT password. DECLARE three BOOLEAN flags: lengthOK, hasDigit, hasUpper. Initialise hasDigit ← FALSE and hasUpper ← FALSE before the scan.
- 2Length check: lengthOK ← (LENGTH(password) >= 8). One line, using the LENGTH function.
- 5Scan for digit and uppercase: FOR loop visiting each character (i ← 1 TO LENGTH(password)). Use MID(password, i, 1) to extract one character. Check if it is between '0' and '9' (set hasDigit ← TRUE) AND check if it is between 'A' and 'Z' (set hasUpper ← TRUE). One pass over the string is enough — both checks happen each iteration.
- 4Combine flags and output result: IF lengthOK AND hasDigit AND hasUpper THEN output 'Password is valid.' ELSE output 'Password is invalid:' followed by ONE line per failing criterion.
- 2Program structure and naming: FOR/NEXT properly paired; IF/ENDIF visible; identifiers like 'lengthOK', 'hasDigit', 'hasUpper' read as boolean tests.
Hints — reveal one at a time, only if stuck
Your pseudocode workspace
1 line