I have saved the sha512 password to DB and I am trying a simple login screen to check the password. I am always getting a password wrong error.
I echoed the result and all text shows correctly. I am not sure what could be wrong here?
Result of the code:
Actual qwerty123!
48a2d06f950fe0bece5ea4749e9db40e2ea17e6353476331839e967b0b7fbd9e4b6c999177e708385f09aca4c7d79884d9b472f4b39d901fffbd5677a9ed26f7 512
48a2d06f950fe0bece5ea4749e9db40e2ea17e6353476331839e967b0b7fbd9e4b6c999177e708385f09aca4c7d79884d9b472f4b39d901fffbd5677a9ed26f7 inside while
48a2d06f950fe0bece5ea4749e9db40e2ea17e6353476331839e967b0b7fbd9e4b6c999177e708385f09aca4c7d79884d9b472f4b39d901fffbd5677a9ed26f7 db
48a2d06f950fe0bece5ea4749e9db40e2ea17e6353476331839e967b0b7fbd9e4b6c999177e708385f09aca4c7d79884d9b472f4b39d901fffbd5677a9ed26f7 Wrong
Here is the code:
<?php
session_start();
ob_start();
require('db/config.php');
$password = "qwerty123!";
echo "Actual " . $password;
echo "</br>";
echo "</br>";
$password = hash('sha512', $password);
echo $password . " 512";
echo "</br>";
echo "</br>";
$username = "admin";
$query = "SELECT * FROM userdetails WHERE username = '$username'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
echo $password . " inside while";
echo "</br>";
echo "</br>";
echo $row["password"] . " db ";
echo "</br>";
echo "</br>";
if(password_verify($row["password"], $password))
{
echo $row["password"] . " Correct ";
}
else
{
echo $row["password"] . " Wrong ";
}
}
}
?>