Bird
0
0

Consider a login system using this vulnerable query:

hard📝 Application Q15 of 15
SQL - Security Basics
Consider a login system using this vulnerable query:
SELECT * FROM users WHERE username = '" + userInput + "' AND password = '" + passInput + "';
If an attacker inputs admin' -- as username and anything as password, what happens and why?
ALogin succeeds without password check because -- comments out rest
BLogin fails due to syntax error from unmatched quotes
CLogin succeeds only if password matches exactly
DLogin fails because input is rejected by the system
Step-by-Step Solution
Solution:
  1. Step 1: Substitute attacker input into query

    The query becomes: SELECT * FROM users WHERE username = 'admin' --' AND password = 'anything';
  2. Step 2: Understand effect of -- comment

    The -- makes the rest of the query a comment, so password check is ignored.
  3. Step 3: Result of query

    The query checks only username = 'admin', allowing login without password.
  4. Final Answer:

    Login succeeds without password check because -- comments out rest -> Option A
  5. Quick Check:

    -- comments out password check = Login bypass [OK]
Quick Trick: SQL comment -- skips password check for login bypass [OK]
Common Mistakes:
  • Assuming syntax error occurs
  • Thinking password is still checked
  • Believing input is blocked automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes