如何以纯文本形式输出 MD5 哈希密码?

发布于 2024-09-07 08:21:35 字数 101 浏览 5 评论 0原文

我有一个网站上的成员密码,使用 MD5 加密并存储在数据库中。我想实现丢失密码功能,如果用户忘记密码,将通过电子邮件发送其凭据。但是如何输出未加密的密码,或者它是一种单向加密,因此不可能?

I have passwords for members on a site encrypted using MD5 and stored in the database. I want to implement a lost password functionality where the user will be emailed their credentials if they forget them. But how to output the unencrypted password or is it one way encryption and hence impossible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

趁微风不噪 2024-09-14 08:21:35

MD5 不是加密——它是一种单向散列。您无法反转单向哈希(理论上您可以找到具有等效哈希的明文,该哈希通常同样好,但您不能在任何合理的时间内完成),因此您只需要设置一个新密码并将其临时通过电子邮件发送给他们,和/或仅向他们提供重置密码的链接。

MD5 isn't encryption - it's a one-way hash. You can't reverse a one-way hash (theoretically you can find a plaintext that has an equivalent hash which is generally as good, but you can't in any reasonable amount of time), so you just need to set a new password and email it to them as a temporary, and/or just provide them a link to reset their password.

快乐很简单 2024-09-14 08:21:35

使用单向哈希的目的是阻止您想要做的事情。如果您可以读取明文密码,那么任何掌握您数据库的人也可以。提示:您如何处理旧备份介质?把它们扔进垃圾桶?众所周知,犯罪分子会在垃圾箱中寻找备份。

不要将用户的密码发回给他们,而是设置一个系统以便他们可以重置密码。在实施之前阅读一些有关此内容的文章。

The point of using a one-way hash is to prevent exactly what you are trying to do. If you can read the plaintext password, then anyone who gets a hold of your database can too. Hint: what do you do with old backup media? Throw them in the trash? Criminals have been known to dumpster-dive for backups.

Instead of sending the user's password back to them, set up a system so they can reset their password. Read up on some articles about this before implementing it.

三生路 2024-09-14 08:21:35

[由于 CodesInChaos 的提示,整个答案被替换;以前的答案已成为历史。]

您不应该使用 MD5 来存储您的密码。如果需要,请参阅 LinkedIn 密码泄露任何更令人信服的理由放弃 MD5。

为了防止密码数据库泄露成为 LinkedIn 的头条新闻,您需要使用明显更好的哈希函数。基于 DES 的 crypt(3) 在 70 年代末可能已经足够好了,但是 现代暴力搜索工具每秒可以轻松测试数百万个候选密码。

相比之下,该工具每秒只能暴力破解数千个 bcrypt 哈希值。 (遗憾的是,他们没有发布 scrypt 计时。)您的 MD5 是数百万 比这些现成的替代品差了好几倍。

要更全面地了解密码安全性,我建议阅读密码安全性:过去、现在、未来幻灯片。

[Entire answer replaced thanks to prompting from CodesInChaos; the previous answer is in history.]

You should not use MD5 to store your passwords. See the LinkedIn password breach if you need any more compelling reason to move away from MD5.

To prevent a password database breach from being the headline news that it was for LinkedIn, you need to use a significantly better hashing function. DES-based crypt(3) might have been good enough in the late 70s, but modern bruteforce searching tools can easily test millions of candidate passwords per second.

By contrast, that same tool is able to bruteforce just thousands of bcrypt hashes per second. (Sadly they do not publish scrypt timings.) Your MD5 is millions of times worse than either of these ready replacements.

For a larger look at password safety, I recommend reading the Password security: past, present, future slides.

池木 2024-09-14 08:21:35

您无法从 MD5 哈希恢复原始密码。这是一种单向哈希函数。

另外,

您不应该向他们提供纯文本密码。您应该做的是要么允许他们更改密码,要么生成一个随机密码供他们使用,然后强制他们更改密码。

No

You can't recover the original password from the MD5 hash. It's a one way hash function.

Also

You shouldn't be providing them with the plain text password. What you should do instead is either allow them to change the password, or generate a random one for them to use and then force them to change it.

忆依然 2024-09-14 08:21:35
  1. 您不应该使用 MD5。使用 sha1 并使用盐,互联网上有很多信息。

  2. 对密码进行哈希处理的目的正是如此。使用它是因为(理论上)无法获取原始密码,因此可以安全地保存密码,并且可以使用它轻松检查密码是否正确。

  3. 几乎所有网站都选择生成新密码并通过电子邮件发送作为忘记密码机制。

    几乎所有

  1. You shouldn't use MD5. Use sha1 and use also a salt, there is a lot of information on the internet.

  2. The purpose of hashing the password is exactly that. It is used because the original password can't be gotten (theorically) so the password would be saved securily and it can be used to check if the password is correct easily.

  3. Allmost all websites chose to generate a new password and send it by email as the forget password mechanism.

心头的小情儿 2024-09-14 08:21:35

虽然有人指出 md5 是一个哈希函数,一个接受密码并返回字符串的函数,例如。 f(密码) == 哈希

可以计算出一个密码,当通过此函数时,它会给出相同的哈希值,例如 f(password) == hash == f(password")

这通常是通过预先计算所有可能的值来完成的密码并将其哈希值存储在彩虹表中(请参阅维基百科条目)。下载这样的彩虹表,但它们太大了!

由于哈希函数中的冲突,您可能无法恢复用户最初使用的相同密码。

While it has been pointed ou that md5 is a hashing function, a function that takes a password and returns a string eg. f(password) == hash.

It IS possible to calculate a password that when put through this function that gives the same hash e.g f(password) == hash == f(password")

This is normally done by precaculating all of the possible passwords and storing the hashes of these in a rainbow table (See Wikipedia entry). It is possible to download such rainbow tables but they are HUGE!

You may not recover the same password that the user originally used due to collisions in the hashing function.

狼性发作 2024-09-14 08:21:35

md5 是一种单向加密/hashing功能。散列后,字符串只能与其散列版本进行比较,而不能解密。

md5 is a one-way encryption/hashing function. Once hashed, a string can only be compared to it's hashed version and not decrypted.

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