Please note: this isn't a duplicate!!! Why? You can use ' but You don't know how :)
I have this PHP code:
<?php
(...)
function escape($str) {
$ret = '';
for($i=0;@$str[$i];$i++)
{
if($str[$i]!='\'')
if($str[$i]!='\\')
if($str[$i]!='"')
if($str[$i]!="\r")
if($str[$i]!="\n")
if($str[$i]!="\x1a")
{
$ret .= $str[$i];
continue;
}
$ret .= '?';
}
return $ret;
}
$pass = escape($_POST['password']);
$query = "select 1 from user_pwd where pass='{$pass}'";
$query = mysql_query($query);
$array = mysql_fetch_array($query);
var_dump($array);
?>
I know that's isn't safe (I know SQL Injection, I can do mysql_real_escape_string or add_slashes, but I just want to know what's wrong :).
EDIT: You can use '. If You send array in POST data: password[0]=1&password[1]=' union select '1 You will do SQL Injection ^^
0mysuperawesomepassword
? Suddenly, my password isn't secure at all. – tim Aug 04 '15 at 17:15