I have a question to solve. Well there's no records of username and password in the database and so one cannot Log in without inserting any records. Is there anyway to exploit the following code and insert records so that we can login.
<?php
$con = mysqli_connect("localhost", "root", "pass", "database");
$username = $_POST["username"];
$password = $_POST["password"];
$logged_in = false;
$query = "SELECT * FROM users WHERE username='$username'";
$result=mysqli_query($con, $query);
if(mysqli_num_rows($result) === 1) {
$row = mysqli_fetch_array($result);
if($row["password"] === $password){
$logged_in = true;
}
if(!$logged_in)
echo("Failed to login");
?>
I have tried the following username = ' OR 1=1 LIMIT 1 ; INSERT INTO users (username,password) VALUES('user','pass') -- username = ' OR 1=1 LIMIT 1 --
Also tell me if there's any other way to exploit the code.