I'm doing a school project, and we're trying to enable logging in for users. Registration works fine, the process hashes the password using password_hash(), and it all goes down to the database. However we're having trouble logging in, and with PHP being kind of hard to debug, have no idea what's wrong with our code.
<?php
// Connect to database
require "connect.php";
$user = $_POST['loginusername'];
$pass = $_POST['loginpassword'];
$query = "SELECT password FROM user WHERE username = '$user'";
$result = mysqli_query($conn, $query);
if(password_verify($pass, $result)) {
// Redirect to Feed-page
header("Location: feed.php");
} else {
echo "Invalid password";
echo $query;
echo $conn->error;
echo $result;
echo $pass;
die();
}
$conn->close();
?>
What we're trying to do here:
- Store the input information into variables
- Store the query string into another variable
- Store the queried result (the hashed password from the database) into yet another variable
- Verify if the entered password matches the one fetched from the db, and redirect
If the verification fails, it should echo stuff into the browser, which doesn't seem to work for us either for some reason...
We're total newbies to PHP, so I'd appreciate if someone could take a look and solve the problem that's had us bash our heads against the wall for a few days now.