note 103229 deleted from function.mysql-real-escape-string by danbrown

From: Date: Sat, 02 Apr 2011 14:56:34 +0000
Subject: note 103229 deleted from function.mysql-real-escape-string by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178433@lists.php.net to get a copy of this message
Note Submitter: advisor//~//code-resource*com ---- <?php /*Another not in regard to injections // We didn't check $_POST['password'], it could be anything the user wanted! For example: $_POST['username'] = 'aidan'; $_POST['password'] = "' OR ''='"; */ //You could escape directly $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); //It's a better practice to hash a password than storing cleartext. $password = md5($_POST['password']); //The hash would prevent the passing of an injection. /*Rather than running an untested query on the database it's a good practice to perform a count on the query values ahead of time before a select or an insert.*/ $query1 = "SELECT count(*) FROM users WHERE user='$username' AND password='$password';"; $result1 = mysql_result(mysql_query($query1),0); if ($result1=='1'){ $query2 = "SELECT * FROM users WHERE user='$username' AND password='$password';"; $result2 = mysql_query($query2); } else { exit(); }

« previous php.notes (#178433) next »