This question is noted as a duplicate and I don't believe it to be as I haven't found any solutions that work for me; but the answer noted is about error posting - this question doesn't regard anything to do with code syntax errors; simply: How do I get a stored hashed password to match the password entered down the road on a login screen?
I'm using PHP 5.5.9 and here is my database info:
Apache/2.4.7 (Ubuntu) Database client version: libmysql - mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $
Server type: MySQL Server version: 5.5.44-0ubuntu0.14.04.1 - (Ubuntu)
PHP extension: MySQLi
I'm starting off by saying I'm barely even a beginner (not even a nOOb and I'm starting with MySQLi. I am aware of PDOs, but this is the skeleton form what I'm using right now for a login screen and it's been days of me losing more and more hair.
Any tips on the following would be very, very much appreciated and thank you in advance.
I can't get the passwords to match (users are inserted into the database using this code: ---> )
$password = $_POST['password'];
$hash = password_hash($password, PASSWORD_DEFAULT);
The $hash value is inserted into the database and looks fine on phpMyAdmin. Then the basic, basic login screen asking for credentials and I always get the 'password doesn't match' failure:
<?php
require_once 'scripts/app_config.php';
require_once 'scripts/database_connection_tbt.php';
$username = mysqli_real_escape_string($db, trim($_REQUEST['username']));
$password = $_POST['password'];
// Look up the user
$query = sprintf("SELECT user_id, username, password FROM pax " .
"WHERE username = '%s' ",
$username);
$result = mysqli_query($db, $query);
$row = mysqli_fetch_assoc($result);
if ($row) {
$hash = $row['password'];
if (password_verify($password, $hash)) {
echo "<br><br>Password match <br><br>";
} else {
echo "<br><br>Password doesn't match<br><br>";
}
}
?>
<html>
<body>
<form action="" method="POST">
<label for="username" id="username">Username:</label>
<input type="text" name="username"><br><br>
<label for="password" id="password">Password:</label>
<input type="password" name="password"><br><br>
<input type="submit" value="Please God, please.">
</form>
</body>
</html>