password_hash returns different value every time

前端 未结 1 1365
庸人自扰
庸人自扰 2020-11-28 15:36

I\'m making a login system, and I want to hash the passwords to make them more secure, but it returns a different hash every time, and can\'t even be verified using password

相关标签:
1条回答
  • 2020-11-28 16:30

    So let's take it one part at a time

    but it returns a different hash every time

    That's the idea. password_hash is designed to generate a random salt every time. This means you have to break each hash individually instead of guessing one salt used for everything and having a huge leg up.

    There's no need to MD5 or do any other hashing. If you want to raise the security of password_hash you pass a higher cost (default cost is 10)

    $password = password_hash($password4, PASSWORD_DEFAULT, ['cost' => 15]);
    

    As to verify

    if(password_verify($password4, $dbpassword))
    

    So $password4 should be your unhashed password and $dbpassword should be the hash you've stored in your database

    0 讨论(0)
提交回复
热议问题