//index.php
<html>
<head>
<!--utf html5 declareren-->
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="cssreset.css">
</head>
<body>
<form action="login.php" method="POST">
username: <input type="text" name="usernamebox" required> <br>
password: <input type="password" name="passwordboxlogin" required> <br>
<input type="submit" value="Login">
</form>
<form action="register.php">
<input type="submit" value="Click here if you want to register">
</form>
</body>
</html>
//login.php
<?php
session_start();
error_reporting(E_ALL);
include ('connect.php');
$username = $_POST['usernamebox'];
$password = $_POST['passwordboxlogin'];
$_SESSION['usernamebox'] = $username;
//$db->query("SELECT * FROM `users` WHERE `username` = '$username'");
//
//$db->query("SELECT * FROM `users` WHERE `password` = '$password'");
//nieuw
$hash = "SELECT password FROM users WHERE username= '$username' ";
if (password_verify($password, $hash))
{
echo 'Password is valid!';
//header("Location: userpage.php");
}
else
{
echo 'Invalid password.';
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
</body>
</html>
I'm an IT student and I can't seem to get this password_verify()
function to work.
I'm basically trying to compare a password hash in mysqli with the password given in the POST form in login.php. The password is hashed correctly to my database.