password_verify如何在不知道盐和成本的情况下验证密码? [英] How can password_verify validate passwords without knowing salt and cost?

查看:146
本文介绍了password_verify如何在不知道盐和成本的情况下验证密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新PHP中的函数 password_verify()密码API检查密码是否与哈希对应。哈希由 password_hash()生成,默认情况下使用随机盐和 cost = 10



我一直认为(尽管我从未研究它)必须将盐存储在数据库中,然后在想要验证密码时,使用相同的成本对给定的盐进行哈希处理。 password_verify()如何在不知道盐份和成本的情况下检查密码? p>由 password_hash()返回的字符串不仅包含哈希值,还包含算法,成本和盐。


The function password_verify() in the new PHP password API checks if the password corresponds to the hash. The hash is generated by password_hash(), that by default uses a random salt and a cost = 10.

I always thought (although I never studied it) that you have to store the salt inside the database and then when you want to verify the password, hash it with the given salt using the same cost. How can password_verify() check the password without knowing salt and cost?

解决方案

The string returned by password_hash() contains not only the hash, but also the algorithm, cost and salt.

这篇关于password_verify如何在不知道盐和成本的情况下验证密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆