You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers authentication and verification as required by OCR J277 Section 2.4. Authentication confirms the identity of a user, while verification confirms that data has been entered or transmitted correctly. Both are essential aspects of producing robust programs.
Authentication is the process of confirming that a user is who they claim to be. It is used to control access to systems, data, and features. Without authentication, anyone could access sensitive information or perform restricted actions.
| Method | Description | Example |
|---|---|---|
| Username and password | User provides a unique identifier and secret password | Logging into a school network |
| Two-factor authentication (2FA) | User provides two forms of identification | Password + code sent to phone |
| Biometric | Uses unique physical characteristics | Fingerprint, face recognition, iris scan |
| Security questions | User answers pre-set personal questions | "What is your mother's maiden name?" |
OCR Pseudocode:
storedUsername = "admin"
storedPassword = "Secure#123"
maxAttempts = 3
attempts = 0
authenticated = false
while attempts < maxAttempts AND authenticated == false
username = input("Enter username: ")
password = input("Enter password: ")
if username == storedUsername AND password == storedPassword then
authenticated = true
print("Login successful!")
else
attempts = attempts + 1
remaining = maxAttempts - attempts
print("Incorrect. " + str(remaining) + " attempts remaining.")
endif
endwhile
if authenticated == false then
print("Account locked. Too many failed attempts.")
endif
Python:
stored_username = "admin"
stored_password = "Secure#123"
max_attempts = 3
attempts = 0
authenticated = False
while attempts < max_attempts and not authenticated:
username = input("Enter username: ")
password = input("Enter password: ")
if username == stored_username and password == stored_password:
authenticated = True
print("Login successful!")
else:
attempts += 1
remaining = max_attempts - attempts
print(f"Incorrect. {remaining} attempts remaining.")
if not authenticated:
print("Account locked. Too many failed attempts.")
OCR Exam Tip: When writing authentication code in the exam, always include: (1) a limited number of attempts, (2) appropriate error messages, and (3) a lockout mechanism after too many failures. These features demonstrate defensive design.
flowchart TD
A[Start login] --> B[attempts = 0]
B --> C{attempts < MAX_ATTEMPTS?}
C -- No --> L[Lock account / Access denied]
C -- Yes --> D[Read username + password]
D --> E{Match stored credentials?}
E -- Yes --> F[authenticated = true]
F --> G[Grant access]
E -- No --> H[attempts = attempts + 1]
H --> I[Show 'Incorrect — N attempts left']
I --> C
A robust authentication system requires strong passwords. Good password policies include:
| Requirement | Purpose |
|---|---|
| Minimum length (e.g. 8+ characters) | Longer passwords are harder to crack |
| Mix of upper and lower case | Increases the number of possible combinations |
| Include numbers | Further increases complexity |
| Include special characters (!@#$%) | Maximum complexity |
| Not a common word or pattern | Prevents dictionary attacks |
OCR Pseudocode:
function checkPasswordStrength(password)
score = 0
if password.length >= 8 then
score = score + 1
endif
hasUpper = false
hasLower = false
hasDigit = false
hasSpecial = false
for i = 0 to password.length - 1
char = password.substring(i, i + 1)
asciiVal = ASC(char)
if asciiVal >= 65 AND asciiVal <= 90 then
hasUpper = true
elseif asciiVal >= 97 AND asciiVal <= 122 then
hasLower = true
elseif asciiVal >= 48 AND asciiVal <= 57 then
hasDigit = true
else
hasSpecial = true
endif
next i
if hasUpper then score = score + 1 endif
if hasLower then score = score + 1 endif
if hasDigit then score = score + 1 endif
if hasSpecial then score = score + 1 endif
return score
endfunction
Verification is the process of checking that data has been entered or transmitted correctly. Unlike validation (which checks if data is reasonable), verification checks that data is accurate — that it matches what was intended.
| Type | Description | How It Works |
|---|---|---|
| Double entry | User enters the data twice | Compare both entries — if they match, the data is likely correct |
| Screen/visual check | User reviews data on screen before confirming | Displays entered data and asks "Is this correct? (Y/N)" |
OCR Pseudocode:
do
email1 = input("Enter your email: ")
email2 = input("Confirm your email: ")
if email1 != email2 then
print("Error: emails do not match. Please try again.")
endif
until email1 == email2
print("Email confirmed: " + email1)
Python:
while True:
email1 = input("Enter your email: ")
email2 = input("Confirm your email: ")
if email1 == email2:
break
print("Error: emails do not match. Please try again.")
print("Email confirmed:", email1)
OCR Pseudocode:
name = input("Enter your name: ")
email = input("Enter your email: ")
phone = input("Enter your phone number: ")
print("Please confirm your details:")
print("Name: " + name)
print("Email: " + email)
print("Phone: " + phone)
confirm = input("Is this correct? (yes/no): ")
if confirm.lower == "yes" then
print("Details saved.")
else
print("Please re-enter your details.")
endif
This is a very commonly tested distinction in the OCR exam:
| Feature | Validation | Verification |
|---|---|---|
| Purpose | Checks data is reasonable/acceptable | Checks data is accurate/correct |
| What it checks | Format, range, type, length, presence | That data matches what was intended |
| Example | Age must be 0–150 | User enters email twice to confirm |
| Can be automated? | Yes — rules can be coded | Partially — double entry is automated; visual check requires human |
| Done by | The computer | The computer and/or the user |
OCR Exam Tip: If asked "What is the difference between validation and verification?", the key answer is: validation checks that data is reasonable and meets certain rules, while verification checks that data has been entered correctly and is accurate. A range check is validation; entering your email twice is verification.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.