Why didn't the other posts help?
Other posts didn't help because one was asking since none worked, despite there are a lot of similar questions.More details
The thing I want to do is to make a user log in using his password. But, the passwords are hashed using bCrypt in the database.When I try to enter the real password, it doesn't work and says that the password is incorrect.
But, when I try to enter the hashed password. It says: "Successfully logged in".
How to make it log in using the real password not the hash?!
Code
Login.php<form method="post" action="loginsession.php">//login
<p>Username <input type="text" name="uid" size="20"> </p>
<p>Password <input type="password" name="pwd" size="20"> </p>
<p><input type="submit" value="Login" name="login"></p>
</form>
Loginsession.php
<?php
session_start();
include ('dbhandler.php');
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$sql = "SELECT * FROM user WHERE uid='$uid' and pwd='$pwd' ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
$encrypted_pwd = password_hash($pwd, PASSWORD_DEFAULT);
$hash = password_verify($pwd,$encrypted_pwd);
$count = mysqli_num_rows($result);
if ($count == 1) {
echo("Logging in...");
$_SESSION['id'] = $row['id'];
$_SESSION['uid'] = $row['uid'];
$_SESSION['pwd'] = $row['pwd'];
echo("<h1 style='color:green;'>Successfully Logged In");
}
else {
echo "Your Login Name or Password is invalid";
die();
}
?>