dongtu7567 2013-08-31 12:07
浏览 80
已采纳

哪个是最好的PHP密码哈希算法? [重复]

This question already has an answer here:

I was just reading a post to create a login system and while reading I saw about password hashing.

We are going to store an sha256 hash which is a string always containing 64 characters.

This article is teaching to use sha256 hash function. After reading this, I did not stop and started to search more about creating secure login system and then I came up with this article by wikiHow. In this article, they are using sha512 hash function. This really confused me that which function am I going to use for my next login system. I still searched google for better article and found this article by crackstation. The writer recommends both sha256 and sha512.

Only cryptographic hash functions may be used to implement password hashing. Hash functions like SHA256, SHA512, RipeMD, and WHIRLPOOL are cryptographic hash functions.

I thought my search is over and I can use sha256 or sha512 function but while searching more I found this SO Question. The accepted answer by Robert K had new things for me. The things about I have never heard before which is bcrypt and scrypt.

All this stuff was written about 2 to 4 years ago.

Question

Which is the best password hashing algorithm used these days for PHP?

</div>
  • 写回答

1条回答 默认 最新

  • doutuan9357 2013-08-31 12:28
    关注

    The main thing here is that you want to choose a hash that is slow. The only feasible attack vector for any of these hashes is brute forcing. Meaning, an attacker can only try all possible passwords one after the other, hashing them using the same algorithm as you did and compare them to the hash. The longer this takes for one password the more infeasible it is to find a match.

    The SHA family of algorithms is designed to be fast, because they're not designed to be used for this purpose. As such they are by themselves somewhat unsuitable for password hashing; though they can be used as part of an algorithm which makes them suitable, such as PBKDF2 (which in short repeats the hashing many thousands of times to stretch it).

    bcrypt and scrypt are explicitly designed to be slow and are as such much more suitable for password hashing. bcrypt is designed to be very expensive in terms of CPU power, while scrypt is designed to be very expensive in terms of memory consumption. CPU power is better scalable using todays hardware than memory is, so scrypt is currently seen as the best thing to use. Though it is very cutting edge at the moment and has seen little support in terms of usable code. bcrypt on the other hand is supported by PHP using password_hash directly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示