程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

How to password_verify() with hash from database

发布于2023-01-19 16:49     阅读(700)     评论(0)     点赞(8)     收藏(3)


Attempting to verify the hash password from the database, with the user input via POST. After some brief research it seems the issue may have something to do with not being able to convert the mysqli_query to a string though I do not know how to do that properly, hence the fetch_object() etc which I added from another SO question. I have also adequately accounted for the length of the has with the column set for varchar(255). Appreciate any help or guidance, thanks.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$password = $_POST['password'];
$db_password = mysqli_query($conn, 'SELECT password FROM sec')->fetch_object()->password;

if (password_verify($password, $db_password)) {
    echo 'Password is valid!';
} else {
    echo 'Invalid password.';
}
?>

解决方案


First get the password hash from the database,then convert the user input password in the hash value.Compare these two values by passing through the function password_verify(), then you will get the proper result.



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/476829/173345e39dccb2b3902a/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

8 0
收藏该文
已收藏

评论内容:(最多支持255个字符)