对于单次使用身份验证,MD5仍然被认为是安全的吗? [英] Is MD5 still considered secure for single use authentications?

查看:180
本文介绍了对于单次使用身份验证,MD5仍然被认为是安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天,由于存储密码的问题,每个人都在拒绝MD5.但是在我只想向可能会使用一次的事物上添加身份验证层的情况下呢?

Everyone is shooting down MD5 these days for its issues in the context of storing passwords. But what about uses where I just want to add a layer of authentication to something that will likely be used once?

这只是一个假设的示例,但是假设我具有允许用户重置其密码的功能.我通过电子邮件向用户发送了一个链接,该链接可以单击以设置新的(随机生成的)密码.

This is just a hypothetical example, but let's say I have a feature to allow a user to reset their password. I email the user a link that they can click to set a new (randomly-generated) password.

我目前的想法是,我将使用一个私有的salt值和几个识别变量生成一个MD5哈希,并使用它来创建链接.

My current thinking is that I'll generate an MD5 hash, using a private salt value, and a couple of identifying variables, and use that to create the link.

让我们说这个功能的盐是"8b769a378411b705"(我对所有重置密码请求都使用相同的盐).其他识别数据是已生成的密码哈希的用户ID和数据库ID.

Let's say the salt for this feature is "8b769a378411b705" (I use the same salt for all reset password requests). The other identifying pieces of data are the user ID and a database ID of the already-generated password hashes.

salt = "8b769a378411b705" (private)
user_id = 123
pw_id = 456
code = md5(salt + " " + user_id + " " + pw_id)

将变为

code = "692a71cd7da194145be209e40fcd3e92"

示例链接: confirm_reset_password.php?user_id = 123& pw_id = 456& code = 692a71cd7da194145be209e40fcd3e92

根据MD5的问题,这是否安全?我应该考虑使用另一种单向哈希,例如SHA-1吗?

Is this considered safe, in light of the issues with MD5? Is there another one-way hash I should consider using, like SHA-1?

我一直在使用带有SHA1的PBKDF2来存储密码,并且我知道它的部分好处在于它的慢"以及生成散列所需的时间.我可以出于这种目的生成那些更高质量的哈希,但是我认为它会适得其反,因为您可以通过用(不正确的)请求轰炸一台服务器来轻易将其屈服,因为每个请求都会导致大量的CPU工作来生成哈希值(尤其是因为我使用了大量迭代).似乎拥有快速"算法可以很好地用于单次使用,但是我想知道MD5是否仍然是最佳选择.

I've been using PBKDF2 with SHA1 for storing passwords, and I understand that part of its benefit is in its "slowness" and how long it takes to generate hashes. I could generate those higher-quality hashes for purposes like this, but I think it can backfire, since you could easily bring a server to its knees by bombarding it with (incorrect) requests, since each one results in a significant CPU job to generate the hash (especially since I am using lots of iterations). It seems that having a "fast" algorithm is good for single use purposes, but I'm wondering if MD5 is still the best choice.

谢谢!

推荐答案

首先,由于许多原因,MD5被认为是不安全的,首先,到目前为止,md5的Rainbow表非常庞大,并且可能覆盖了大多数哈希空间.其次,已知的攻击使您可以创建哈希冲突(以将产生相同md5输出的方式伪装其他数据).它的128位的三分之二,以今天的短.

First of all MD5 is considered insecure for many reasons, first of all, rainbow tables for md5 are enormous by now, and probably cover most of the hash space. Second, there are known attacks that allow you to create hash collisions (to disguise other data in the manner which will produce the same md5 output). Third its 128bits, for today its short.

现在回到您的问题,如果您不托管任何对安全性要求很高的应用程序,则不存储任何私有数据,医疗数据或任何其他受国家法律控制"的数据,那么使用md5就是您的好选择.进入您的算法,它不是不安全的,但是它也不是超级安全的,这是您的选择.您唯一需要添加的就是新鲜度,即某种时间戳,可以告诉您消息的有效期.其次,您的算法不提供重播保护:),如果用户一次使用此链接并将其留在浏览器中,攻击者可能会再次使用此链接来重置此密码.这是一个非常严重的缺陷.因此,您可能需要修复它.

Now back to your question, if you are not hosting any security-critical app, you do not store any private data, medical data, or any other "country law controlled" data, you are good with md5. Going into your algorithm, it's not insecure, but it's not super secure either, its your choice. Only thing you should add is freshness, that is some sort of timestamp telling you the validity period of your message. Secondly, your algorithm does not offer a replay protection :), if user will use this link once and leave it in browser, attacker may use this link again to reset this password. It's pretty serious flaw. So you might want to fix it.

但是我想告诉你其他事情.如果不是绝对必要,请不要使用加密!我的谦虚要求.您的密码重置方案可以轻松实现,无需加密,并具有重放保护,并具有更高的安全性.您需要做的就是在表"pw_reset_hash"和"reset_validity"中添加其他列,并用RANDOM编号和有效日期填充它们.向用户发出一个随机数,并在使用后清除字段,请事先检查其有效性.瞧:)因为它是随机的,所以它可能比任何哈希算法都更安全.但是请使用安全的PRNG.

But I want to tell you some other thing. DO NOT USE CRYPTO IF IT IS NOT ABSOLUTELY NECESSARY! My humble request. Your password resetting scheme can be easily implemented without crypto and with replay protection, and far more security. All you need to do is add an additional columns to your table "pw_reset_hash" and "reset_validity", and populate them with RANDOM number, and valid date. Issue a user a random number, and clear the fields after it's used, check for validity beforehand. And voila :) Since it's random its probably more secure than any hashing algorithm. But use a secure PRNG.

这篇关于对于单次使用身份验证,MD5仍然被认为是安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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