使用不同的身份验证机制时如何安全地存储密码

发布于 2024-12-17 17:12:18 字数 373 浏览 3 评论 0原文

对于一个有趣的项目,我想支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尛丟丟 2024-12-24 17:12:18

DIGEST-MD5 规范 告诉您服务器需要为该身份验证方法存储什么内容:

3.9 存储密码

摘要式身份验证要求身份验证代理
(通常是服务器)存储一些从用户名派生的数据
和与给定领域关联的“密码文件”中的密码。
通常,这可能包含由用户名和 H({
用户名值,“:”,领域值,“:”,密码})
,这是
足以如上所述计算 H(A1),无需直接
暴露用户的密码。

...因此,您需要为 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:

3.9 Storing passwords

Digest authentication requires that the authenticating agent
(usually the server) store some data derived from the user's name
and password in a "password file" associated with a given realm.
Normally this might contain pairs consisting of username and H({
username-value, ":", realm-value, ":", passwd })
, which is
adequate to compute H(A1) as described above without directly
exposing the user's password.

...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.

迷鸟归林 2024-12-24 17:12:18

不要以明文形式存储密码。存储散列并与散列进行比较。您可以使用纯密码轻松获取哈希值。

以下是如何创建良好的哈希:

function hash_password($password, $nonce) {
  global $site_key;
  return hash_hmac('sha512', $password . $nonce, $site_key);
}

请参阅 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:

function hash_password($password, $nonce) {
  global $site_key;
  return hash_hmac('sha512', $password . $nonce, $site_key);
}

See Secure hash and salt for PHP passwords

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文