Why is php's password_hash so slow?

后端 未结 3 620
有刺的猬
有刺的猬 2021-02-14 21:13

I am using password_hash for password encryption. However there is a strange question, password_hash cost very long time. Here is a sample code. this c

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 21:51

    Yes, it's normal. That's what the cost parameter is for: it allows you to tweak the iteration count, making the hash slower or faster as needed.

    You should always make the hash as slow as possible and as fast as necessary. The reason being that the only feasible attack on a password hash is brute force. You want to make the cost so large that it takes prohibitively long to simple brute force all possible values. That's your only real defence against attackers with password hashing to begin with.

    One whole second seems prohibitively for your own use. You should lower that cost a bit to stay within a few hundred milliseconds at most. Adjust to your target systems as needed.

提交回复
热议问题