note 93674 added to security.database.sql-injection
| From: | callix at osu1 dot php dot net | Date: | Tue, 22 Sep 2009 14:59:25 +0000 |
| Subject: | note 93674 added to security.database.sql-injection | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-160937@lists.php.net to get a copy of this message | ||
To limit the risk of SQL injection when validating user/password, good practice (after sanitizing
the user name) is to retrieve the password with the query and validate it in php, as opposed to
using it in the WHERE clause:
<?php
$l_user = addslashes($user);
$l_pwd = addslashes($pwd);
$query = "SELECT password FROM usertable WHERE username='$l_user'";
/*
Execute query with appropriate db function
...
Retrieve password field into $password with appropriate db function
*/
if($password != md5($l_pwd)) {
die("You fool!");
}
echo "Welcome!"
...
?>
----
Server IP: 64.71.164.2
Probable Submitter: 212.147.5.242
----
Manual Page -- http://www.php.net/manual/en/security.database.sql-injection.php
Edit -- https://master.php.net/note/edit/93674
Del: integrated -- https://master.php.net/note/delete/93674/integrated
Del: useless -- https://master.php.net/note/delete/93674/useless
Del: bad code -- https://master.php.net/note/delete/93674/bad+code
Del: spam -- https://master.php.net/note/delete/93674/spam
Del: non-english -- https://master.php.net/note/delete/93674/non-english
Del: in docs -- https://master.php.net/note/delete/93674/in+docs
Del: other reasons-- https://master.php.net/note/delete/93674
Reject -- https://master.php.net/note/reject/93674
Search -- https://master.php.net/manage/user-notes.php