PHP中的Md5替代? [英] Md5 Alternative in PHP?

查看:163
本文介绍了PHP中的Md5替代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

对于PHP加密用户数据(如密码和其他安全数据),Md5算法的最佳选择是什么? >

SHA512不是一个可怕的选择。但是,对于大多数密码来说,这是不久之后的破解。采取杰夫的建议。使用 bcrypt PBKDF2 。它们耐EC2或其他并行处理技术。可能没有免疫,但是有抵抗力。



在这种情况下,更好的哈希不是更好的原因是 ABC MD5成为一个值,SHA512中的 ABC 成为一个值。计算所有3个字母的密码是对于SHA512而言比MD5更容易。关键是要做很难。这意味着一个缓慢的哈希,一个使用大量的RAM,和/或一个在EC2上不能轻易完成的。



最好的选择是不要使用一切密码就完了。确定您的网站真正需要登录,如果是,请尝试使用第三方提供商。如果这不是一个选项,请考虑RSA的密码+令牌。只有在没有其他可行选项的情况下才可以单独使用密码。



当散列密码时,密钥是哈希(密码+盐),盐需要每个用户独一无二,也应该是难以估量的。使用用户名符合第一个标准,对于每个用户来说,优于没有盐或相同的盐,,但每个用户的唯一随机盐是更好的选择。理想情况下,在单独的数据库中,如果不是位置,用自己的凭据。还应该键入不在用户名上,而是键入user_id甚至是user_id的散列。您希望该数据库是SQL注入证明。接受用户没有输入的输入是一个很好的方法。而且你会明智地让查询本身进行散列。慢?是的,这也是一件好事。



盐本身应该包含所有难以预测的数据。用户名+用户Id +时间戳+来自dev / urandom的垃圾+最新的推文,其中包含taco。越长越好



摘要:hash = bcrypt(password + salt),salt = sha512(username + user_id + timestamp + microtimestamp + dev / urandom位+其他噪音)。



如果你仍然担心所有这一切。随身携带SHA512加密密码。你会获得SHA512的力量,当破解只显示出更强大的暴力加密散列。


What's the best alternative to the Md5 algorithm for PHP for encrypting user data like passwords and other secure data, stored in MySQL databases?

解决方案

SHA512 is not a terrible choice. But it won't be long before it is cracked for most lengths of passwords. Take Jeff's Advice. Use bcrypt or PBKDF2. They are resistant to EC2 or other parallel processing techniques. Probably not immune, but resistant.

The reason a better hash isn't better in this case is ABC in MD5 becomes one value and ABC in SHA512 becomes one value. Calculating all the 3 letter passwords is actually easier for SHA512 than it was for MD5. The key is to be hard to do. That means a slow hash, one that uses a lot of RAM, and/or one that can't be easily done on EC2.

The best choice is to NOT use passwords alone anymore at all. Decide if login is really needed for your site, and if it is, try to use a 3rd party provider first. If that's not an option consider a password + token from RSA. Only use a password alone if you have no other viable options.

When hashing a password the key is to hash(password + salt) and the salt needs to be unique per user, and should also be difficult or impossible to guess. Using the Username meets the first criteria and is better than no salt or the same salt for each user, but a unique random salt for each user is a better choice. Ideally in a separate database, if not location, with its own credentials. It should also be keyed not on the username, but on the user_id or even a hash of the user_id. You want that database to be SQL injection proof. Accepting no input from the user that isn't hashed is a good way to do that. And you would be wise to let the query itself do the hashing. Slow? Yes, and that's ALSO a good thing.

The salt itself should contain all the hard to predict data it can get. Username + User Id + Timestamp + garbage from dev/urandom + the latest tweet with the word taco in it. Longer the better. SHA512 is a good choice of hash here.

Summary: hash = bcrypt(password + salt), salt = sha512(username + user_id + timestamp + microtimestamp + dev/urandom bits + other noise).

If you are still worried after all of that. Feel free to SHA512 the bcrypted password. You'll gain the strength of SHA512, which when cracked only reveals a much harder to brute force bcrypted hash.

这篇关于PHP中的Md5替代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆