I have a web app thats built with Laravel. I'm working on another site but not with Laravel. I need to authenticate users on this new site with the users table on the Laravel site database. The passwords are hashed with bcrypt.
I tried to verify the passwords before the users can login but I seem to be missing something out . Could anyone please assist?
<?php
if (isset($_POST['login'])) {
$user = mysqli_real_escape_string($_POST['email']);
$pass = mysqli_real_escape_string($_POST['password']); //input entered
$dpass = password_hash('$pass', PASSWORD_DEFAULT)."\n";
echo $dpass;
$query = mysqli_query($conn, "SELECT * FROM users WHERE `email` = '$user' AND `password` ='$pass'");
$numrows = mysqli_num_rows($query);
if ($numrows != 0) {
while ($row = mysqli_fetch_assoc($query)) {
$dbemail = $row['email'];
$dbpassword = $row['password'];
}
if ($user === $dbemail && password_verify($pass, $dbpassword)) {
session_start();
$_SESSION['email'] = $username;
// Redirect Browser
header("Location:mentor.php");
}
} else {
echo "<div class='alert alert-danger alert-dismissible'>
<a href='#' class='close' data-dismiss='alert' aria-label='close'>×</a>
<strong>Warning!</strong> Invalid credentials.
</div>";
}
}
?>