During data base querry, you might ask the user for a user ID and password, then check for the user by passing the database a query and checking the result.
Code:
SELECT * FROM users WHERE name='$username' AND pass='$password';
However, if the user who's logging in is devious, he may enter the following as his password:
This results in the query being sent to the database as:
Code:
SELECT * FROM users WHERE name='known_user' AND pass='' OR '1'='1';
This will return the username without validating the password -- the malicious user has gained entry to your application as a user of his choice.
To alleviate this problem, you need to escape dangerous characters from the user-submitted values, most particularly the single quotes ('). The simplest way to do this is to use PHP's addslashes() function.
Code:
$username = addslashes($_POST["username"]);
$password = addslashes($_POST["password"]);
Bookmarks