<!doctype html>
<html lang="en">
</head>
<body>
<form action="index.php" class="signin-form" method="post">
<div class="form-group mb-3">
<label class="label" for="name">Username</label>
<input type="text" class="form-control" name="username" placeholder="Username" required>
</div>
<div class="form-group mb-3">
<label class="label" for="password">Password</label>
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<div class="form-group">
<button type="submit" class="form-control btn btn-primary rounded submit px-3">Sign In</button>
</div>
<div class="form-group d-md-flex">
<div class="w-50 text-left">
<label class="checkbox-wrap checkbox-primary mb-0">Remember Me
<input type="checkbox" checked>
<span class="checkmark"></span>
</label>
</div>
<div class="w-50 text-md-right">
<a href="#">Forgot Password</a>
</div>
</div>
</form>
<?php
$localhost = "localhost";
$username = "root";
$password = "";
$database = "users";
$usr = $_POST['username'];
$pwd = $_POST["password"];
$conn = mysqli_connect($localhost,$username,$password,$database);
if($conn){
$query = "SELECT password FROM accounts ";
$query_result = mysqli_query($conn,$query);
$num = mysqli_num_rows($query_result);
if($num==1)
{
while($row=mysqli_fetch_assoc($result)){
if(password_verify($pwd,$row['password']))
{
echo "Match";
}
}
}
}
?>
</body>
</html>
I store my password in varchar(255) and insert it using function password_hash() , Initially I am inserting password using mysql insert option and also selecting password_hash() option from function menu while inserting.
Thereafter when I test the php (say I have inserted username = test and password = test) against data already in the database , the password_verif() never return true despite both the string being equal
source https://stackoverflow.com/questions/71117098/why-php-script-does-not-verify-hashed-password
No comments:
Post a Comment