Multiple choice › Defensive data input handling
Defensive data input handling
1. Defensive data input handling
Which technique BEST protects a login form from SQL injection?
- Showing detailed database error messages to the user
- Using a larger font on the form
- Making the password field longer on screen
- Parameterised queries combined with input validation
Answer
D
Parameterised queries keep user data separate from SQL commands, and validation rejects unexpected input. Detailed error messages help attackers.
2. Defensive data input handling
What is the difference between input validation and input sanitisation?
- Validation happens only after the data is saved; sanitisation happens before
- Validation encrypts the input; sanitisation decrypts it
- Validation checks that input meets the rules and rejects it if not; sanitisation cleans or removes harmful characters from input
- They are the same process with different names
Answer
C
Validation = is this acceptable (type, range, format, length)? Sanitisation = make unsafe input safe (e.g. escape or strip < > and quotes).
3. Defensive data input handling
A program asks for an age and the user types 'abc'. Which is the BEST error-handling response?
- Silently set the age to 0 and continue
- Let the program crash so the developer sees the error
- Catch the error, tell the user a whole number is needed and ask again
- Display the full stack trace to the user
Answer
C
Good error handling anticipates bad input, gives a clear message and lets the user recover, without exposing internal details.