So I have been reading a lot about prepared statements and keep getting varied answers regarding how well prepared statements protect from mysql injections. Some people say it fully covers it while others say theres still some small work arounds or something. Pretty much I just wanted to make sure this code I have is safe and know if there are actually any holes in prepared statements:
<?php
ignore_user_abort(true);
$user = $_REQUEST['username'];
$pass = $_REQUEST['password'];
if (isset($user) && isset($pass)) {
require('/var/www/data/config.php'); //contains the db connection
if ($stmt = mysqli_prepare($mysqli, "SELECT password FROM users WHERE username=?")) {
mysqli_stmt_bind_param($stmt, 's', $user);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $gpass);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
if ($gpass) {
require('/var/www/data/handles/fCrypt.php');
$chk = verify($pass, $gpass); //custom blowfish validation
if ($chk) {
//password correct, continue
} else {
mysqli_close($mysqli);
//echo invalid password stuff
}
} else {
mysqli_close($mysqli);
//echo invalid username stuff
}
} else {
mysqli_close($mysqli);
die('Query Error');
}
} else {
die('Invalid Request');
}
?>