Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1if not age.isdigit(): | ARaw user input is put straight into the SQL query without validation, so harmful input like ' OR '1'='1 can change the query | |
| 2if len(username) > 20: | BChecks the length of the input and rejects a username that is too long | |
| 3Validate the format of input by only accepting a postcode made of exactly 4 digits | Cif len(code) == 4 and code.isdigit(): | |
| 4Protect against harmful input by refusing text that contains characters used in injection attacks | Dif "'" in text or "<" in text: | |
| 5age = input("Age: ") print("Next year: ", age + 1) | EThe input was used straight away without checking that it is a number, so a letter or text will crash the program | |
| 6query = "SELECT * FROM users WHERE name='" + name + "'" | FChecks that the age typed in is made only of digits and rejects it if it is not a whole number |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
input validation — Checking that data a user enters is the expected type, length and format before the program uses it, so bad or harmful input is rejected.if age.isdigit():
age = int(age)if len(password) >= 8:
print("Accepted")if 0 <= age <= 120:
print("Valid age")while not age.isdigit():
age = input("Age: ")if "'" in text:
print("Rejected")