I am having some issues with using password_hash and password_verify, I have the code below, and by my eyes should work perfectly. But password_verify always returns false when the user logs on. Any help would be appreciated;
Password Register Script
$passVerifyString = $_GET["verify"];
$resetPasswordOne = $_POST['inputPasswordOne'];
$resetPasswordTwo = $_POST['inputPasswordTwo'];
if($resetPasswordOne != $resetPasswordTwo){
$resetError = "The passwords do not match";
}
else {
if (isset($_POST['submit'])) {
$updatedPass = password_hash($resetPasswordOne, PASSWORD_DEFAULT);
$passUpdateSql = "UPDATE companyUsers SET userPass='$updatedPass', passVerify='' WHERE passVerify='$passVerifyString'";
if (mysqli_query($db, $passUpdateSql)) {
$resetError = "Your password has been sucessfully reset";
}
}
}
User Logon Script (reduced version)
$username=$_POST['username'];
$password=$_POST['password'];
// To protect MySQL injection for Security purpose
$username = stripslashes($username);
$password = stripslashes($password);
// SQL query to fetch information of registered users and finds user match.
$logon_sql = mysqli_query($db,"SELECT userId, userPass FROM companyUsers WHERE userLogin='$username'");
$row = mysqli_fetch_array($logon_sql,MYSQLI_ASSOC);
$userId = $row['userId'];
$hash = $row['userPass'];
$_SESSION['userId']=$userId;
if(empty($userId)){
$error = "Incorrect Username";
}
else{
if (password_verify($password, $hash)) {
$error= "Verified, Logging In";
header("location: https://XXXXXXXXXXXXXXXX/home.php");
}
else {
$error = "Incorrect Password";
}
Thanks all, I know this code doesn't follow the greatest security protocol, this is just the testing version before I protect it.