How can password_verify validate passwords without

2019-03-27 06:44发布

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条回答
爷的心禁止访问
2楼-- · 2019-03-27 07:00

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

查看更多
登录 后发表回答