I wrote simple login script using PHP and mySQLi. Problem is that password_verify()
function returns empty variable. I have double checked everything, but I don't see it. Where is the problem ?
session_start();
if (isset($_POST["submit"])) {
include_once("dbh.inc.php");
// Get data from POST request
$uid = mysqli_real_escape_string($conn, $_POST["uid"]);
$passwd = mysqli_real_escape_string($conn, $_POST["passwd"]);
// Check if fields are empty
if (empty($uid) || empty($passwd)) {
echo "One or more of inputs was left blank";
exit();
} else {
$result = mysqli_query($conn, "SELECT * FROM users WHERE uid='$uid' OR email='$uid';");
if (mysqli_num_rows($result) < 1) {
// Forward to login page with GET failed=notFound
header("Location: ../login.php?failed=notFound");
exit();
} else {
if ($row = mysqli_fetch_assoc($result)) {
$pwdCheck = password_verify($passwd, $row["pwd"]);
if (!$pwdCheck) {
header("Location: ../login.php?failed=pwd");
exit();
} elseif ($pwdCheck) {
// Login here
$_SESSION["id"] = $row["id"];
// Forward to login page with GET failed=0
header("Location: ../login.php?failed=0");
exit();
}
}
}
}
} else {
header("Location: ../login.php");
exit();
}