Why is php's password_hash so slow?

后端 未结 4 1284
时光取名叫无心
时光取名叫无心 2021-02-14 20:44

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

4条回答
  •  臣服心动
    2021-02-14 21:33

    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.

提交回复
热议问题