安全的密码存储
我正在开发一项用户必须登录的网络服务。我将用户数据存储在 SQL 数据库中,并通过 PHP。但我不想公开存储它。如何在 PHP 中加密密码,以便只有知道密码的人才能解锁?
我知道像 phpBB 这样的服务对存储的密码使用某种隐藏/加密。
I'm developing a web service where users must login. I will store user data in an SQL database and input/output via PHP. But I don't want to store it openly. How do I encrypt the passwords in PHP so only those who knows the password can unlock it?
I know services like phpBB uses some sort of hiding/encryption on stored passwords.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您需要使用适当的安全算法对密码进行加盐和哈希处理。
You need to salt and hash the password, using an appropriately secure algorithm.
确保密码存储方案安全的最简单方法是使用标准库。
由于安全性往往比大多数程序员单独解决的要复杂得多,而且有更多看不见的搞砸的可能性,因此使用标准库几乎总是最简单和最安全(如果不是唯一)的可用选项。
有关详细信息,请参阅此答案
The easiest way to get your password storage scheme secure is by using a standard library.
Because security tends to be a lot more complicated and with more invisible screw up possibilities than most programmers could tackle alone, using a standard library is almost always easiest and most secure (if not the only) available option.
See this answer for more info
您可能想要对密码进行哈希处理 - 而不是对其进行加密。 查看 SHA-1。散列意味着您无法像加密那样检索原始数据。相反,您所做的是对用户输入进行哈希处理,并将其与数据库中的哈希值进行比较,以查看他们是否获得了正确的密码。这样做可以提高安全性,就好像您的数据库曾经受到损害一样 - 一堆哈希值是无用的。
You probably want to hash the password - not encrypt it. Check out SHA-1. Hashing means that you cannot retrieve the original data as you can with encryption. Instead what you do is hash the users input and compare it to the hash in the database to see if they've got the right password. Doing this increases security as if your database was ever compromised - a bunch of hashes are useless.
嗯,你不应该用 MD5 加密它们(这并不真正安全,大多数黑客都有转换表)。
因此,您可以使用 SHA1(通常使用)对其进行哈希处理。
如果你想要更多的安全性,你可以添加更多的
salt
,它是一个key,你可以像这样添加(只是一个例子,通常使用):这个组合可以与许多语言。
Well, you shouldn't encrypt them with MD5 (which is not really secured, most hackers have conversion tables).
Hence, you can hash it with SHA1 (which is usually used).
If you want more security, you can add more
salt
which is a key you can add like this (just an example, usually used) :This combination can be used with many language.
使用 SHA-1(sha1 php 内置函数)对密码进行哈希处理,并进行多次加盐递归(与上面答案中的代码相同,仅循环几次)。这应该是足够的保护,所以即使入侵者以某种方式获得了哈希值,他们也不应该能够破解它们......
Hash passwords in SHA-1 (sha1 php inbuilt function) with several recursions of salting (same code in the answers above, only loop through several times). This should be sufficient protection, so even if the intruders somehow get their hands on the hashes, they shouldn't be able to crack them...
保存 MD5 哈希值,并添加盐以使其更安全。
Save an MD5 hash and to make it more secure, add a salt.
可以对密码进行哈希处理(最好使用盐):
或加密存储(仅当您的 MySQL 连接受 SSL 保护时):
There is the possibility to hash passwords (preferably with a salt):
Or store encrypted (only if your MySQL connection is SSL secured):