- Home
- Lessons
- GCSE & IGCSE Computer Science
- Validation and authentication
Validation and authentication
🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.
Users make mistakes and some try to break things. Validation checks data is sensible; authentication checks who someone is.
Validation checks
Validation with a loop
Keep asking until the data is valid:
age = int(input("Age: "))
while age < 11 or age > 18:
print("Out of range")
age = int(input("Age: "))
print("Accepted")
age = int(input("Age: "))
while age < 11 or age > 18:
print("Out of range")
age = int(input("Age: "))
print("Accepted")
Authentication
Authentication confirms that users are who they say they are.
The usual method is an ID and password.
A lookup checks the entered details against stored records, for example a list or a file of users.
users = [["amir", "Cat#42"], ["beth", "Sun!77"]]
uid = input("ID: ")
pw = input("Password: ")
found = False
for user in users:
if user[0] == uid and user[1] == pw:
found = True
print(found)
The usual method is an ID and password.
A lookup checks the entered details against stored records, for example a list or a file of users.
users = [["amir", "Cat#42"], ["beth", "Sun!77"]]
uid = input("ID: ")
pw = input("Password: ")
found = False
for user in users:
if user[0] == uid and user[1] == pw:
found = True
print(found)
Which validation checks suit a UK mobile number entered as 11 digits starting 07?
- It must be entered: presence check.
- It must be 11 characters: length check.
- It must start with 07 and contain only digits: pattern check.
Answer: Presence, length and pattern checks
Presence, length, range and pattern checks make sure data is sensible. A while loop re-asks until valid. Authentication confirms identity, usually by looking up an ID and password.
The interactive lesson includes the diagrams for this topic.
Check you have got it
Answer 7 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.