How can password_verify validate passwords without knowing salt and cost?

十年热恋 提交于 2019-12-09 09:52:11

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/16875158/how-can-password-verify-validate-passwords-without-knowing-salt-and-cost

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!