0

im trying to make a Login System for my Website, i am able to Hash a password and insert the Hashed Data into the Database, however retrieving it is a little bit different.

I Am Making my Page search for the (Hashed Password) for the Given Username in the previous page, as well as the given Password from the previous page. Then getting my code to see if the two passwords match, however, i don't get a value return. And Yes, i am Echoing it, and suggestions?

<?php
session_start();

include 'dbh.php';

$Username = $_POST['Username'];
$Password = $_POST['Password'];

$sql = "SELECT * FROM account WHERE Username='$Username'";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
    $UsernameActualhashedPassword = $row['Password'];
}

$input = $Password;

echo $input;
echo $UsernameActualhashedPassword;
echo password_verify($input, $UsernameActualhashedPassword);
JoshuaMicallef
  • 15
  • 1
  • 1
  • 5

1 Answers1

0

Try this one and look for Sanitizing user for secure login

<?php
session_start();

include 'dbh.php';

$Username = $_POST['Username'];
$Password = $_POST['Password'];
$hashpass = hash_fun($password); // use the same hash function which you have used in the signup
$sql = "SELECT count(*) FROM account WHERE Username='$Username' and 
password='$hashpass'";
 $result = $conn->query($sql);
 if($result>0)
  echo "Login success";
 else echo "wrong username or password";
?>
flamelite
  • 2,654
  • 3
  • 22
  • 42