简体   繁体   English

password_verify似乎不起作用

[英]password_verify does not seem to work

I'm completely new to the password_hash and verify functions, but I've read the documentations about them on the default php website. 我对password_hash和验证功能是完全陌生的,但是我已经在默认的php网站上阅读了有关它们的文档。 I have problems with logging in when I hash passwords using password_hash. 使用password_hash哈希密码时,登录时出现问题。 They are already hashed in the database. 它们已经在数据库中散列了。

This is my code I use to verify if the password entered in the form matches with the hash in the database (that has been generated with password_hash in a register form): 这是我用来验证在表单中输入的密码是否与数据库中的哈希(已通过注册表单中的password_hash生成的)匹配的代码:

    $username = $kunaiDB->real_escape_string($_POST["uname"]);
    $password = $kunaiDB->real_escape_string($_POST["pword"]);

    $kunaiLoginQuery = "SELECT * FROM kunai_users";

    $kunaiLoginQueryResult = $kunaiDB->query($kunaiLoginQuery);
    $controlhash = $kunaiLoginQueryResult->fetch_array();
    $db_pw_res = $controlhash["user_pw"];

    if(password_verify($password, $db_pw_res)) {
        echo "Passwords match!";
    } else { echo "Passwords do not match!"; }

Whenever I log in it fails. 每当我登录失败。 I've tried to search for similar solutions but so far I've not found anything that worked. 我试图寻找类似的解决方案,但到目前为止,我还没有找到任何可行的解决方案。 All help is appreciated :-) 感谢所有帮助:-)

Their is mistake in your SQL query. 他们是您的SQL查询错误。 Add a WHERE clause. 添加一个WHERE子句。 Something like this 像这样

SELECT * from table_name WHERE user_name_field = '{$username}'

And instead of 而不是

$controlhash = $kunaiLoginQueryResult->fetch_array();

Type 类型

$controlhash = $kunaiLoginQueryResult->fetch_assoc(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM