SQL Injection: The Art of Authentication Bypass

Today we'll look at a classic SQL Injection vulnerability using a hypothetical website written in PHP. PHP-based applications can be exposed to this type of attack when user input is handled or filtered incorrectly.
What is the problem?
If an administrator login form does not properly protect against malicious input, an attacker may attempt to manipulate the SQL query through an input field.
Payload breakdown
admin' OR '1'='1
When this string is entered into the username field, a vulnerable application may construct a query similar to:
SELECT * FROM users WHERE username = 'admin' OR '1'='1' AND password = '...'
What happens here:
'admin'closes the original quote around the username.ORis a logical SQL operator.'1'='1'is a condition that always evaluates to true.
Depending on the query structure and operator precedence, such a construction can alter the intended authentication logic and potentially lead to an authentication bypass. This demonstrates why user input must never be directly concatenated into SQL queries.
How can you protect against it?
Never trust user input. Use Prepared Statements and PDO in PHP to keep user-supplied data separate from SQL code.
$stmt = $pdo->prepare(
'SELECT * FROM users WHERE username = :username AND password = :password'
);
$stmt->execute([
'username' => $username,
'password' => $password
]);
Status: the owner of the tested resource has already been informed about the vulnerability and is working on fixing it.