使用不同的身份验证机制时如何安全地存储密码
对于一个有趣的项目,我想支持 SASL 机制进行身份验证,尤其是 PLAIN 和 DIGEST-MD5。
我的问题是:如果我需要支持这两种身份验证方式,如何安全地存储用户密码?
仅使用 PLAIN 身份验证就非常简单,我只需使用 bcrypt 存储密码,并使用 bcrypt_compare 函数将用户提交的密码与存储的密码进行比较。
但是,当 DIGEST-MD5 也应该可行时,如何安全地存储密码呢? 我是否应该存储整个计算出的响应并将其用于普通比较? 或者还有其他办法吗?
//编辑:关于“有趣”的项目。目前这是一个有趣的项目,但没有人知道在某个时候它是否会成为一个不有趣的项目。我不想仅仅因为这是一个有趣的项目而降低安全性。
For a fun project I want to support the SASL Mechanisms for authentication, especially PLAIN and DIGEST-MD5.
My question is: how can I store the users' password securely if I need to support those two ways of authentication?
With only PLAIN auth it would be really easy, I just store the password with bcrypt and compare the user submitted password with the stored pw using the bcrypt_compare function.
But how can I store the password securely when also DIGEST-MD5 should be possible?
Should I store the whole calculated response and use that also for the PLAIN comparison?
Or is there some other way?
//Edit: Regarding the "fun"-project. At the moment it is a fun project but no one knows if it will be a non-fun project at some point. And I don't want to decrease the security just because it's a fun project..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DIGEST-MD5 规范 告诉您服务器需要为该身份验证方法存储什么内容:
...因此,您需要为 DIGEST-MD5 存储的只是
H({ username-value, ":",realm-value, ":", passwd })
。您可以单独存储 bcrypt 哈希以用于
PLAIN
身份验证,也可以仅使用 DIGEST-MD5 值。如果您存储单独的值,那么您可以允许您的用户有选择地关闭 DIGEST-MD5 身份验证,这将允许您从这些用户的数据库中删除该(容易被暴力破解的)信息。The DIGEST-MD5 specification tells you what a server needs to store for that authentication method:
...so all you need to store for DIGEST-MD5 is
H({ username-value, ":", realm-value, ":", passwd })
.You could separately store a bcrypt hash to use for
PLAIN
authentication, or you could just use the DIGEST-MD5 value. If you stored separate values then you could allow your users to selectively turn off DIGEST-MD5 authentication, which would allow you to remove that (easily-bruteforced) information from the database for those users.不要以明文形式存储密码。存储散列并与散列进行比较。您可以使用纯密码轻松获取哈希值。
以下是如何创建良好的哈希:
请参阅 PHP 密码的安全哈希和盐< /a>
Don't store the password in plain. Store the hash and compaire in both with the hash. You can easily get the hash with the plain password.
Here ist how to create a good hash:
See Secure hash and salt for PHP passwords