php 如何使用php解密散列密码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12174104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to decrypt hashed password using php?
提问by Naveen Gamage
I'm currently using MD5 and SHA1 to save my users' passwords in a database but I don't know how to get them back in plain text. I tried to roll back same code I used to encrypt passwords but it gives me an error.
我目前正在使用 MD5 和 SHA1 将我的用户密码保存在数据库中,但我不知道如何以纯文本形式获取它们。我试图回滚我用来加密密码的相同代码,但它给了我一个错误。
Code I'm using to encrypt passwords:
我用来加密密码的代码:
$hashedpassword = md5(md5(sha1(sha1(md5($normalpassword)))));
I tried to do the same thing back like this
我试着像这样做同样的事情
$normalpassword = md5(md5(sha1(sha1(md5($hashedpassword)))));
Then I realized it's something funny :( !! Please help me...
然后我意识到这很有趣:( !!请帮帮我...
回答by galymzhan
MD5 and SHA-1 are one-way hash functions, meaning you can't get back an original string from a hash value.
MD5 和 SHA-1 是单向哈希函数,这意味着您无法从哈希值中取回原始字符串。
回答by Henrik Karlsson
You can't. Hashing is one way, you'll have to generate a new hash of the input at the login form and check if it is equal to the stored hash.
你不能。散列是一种方法,您必须在登录表单中生成输入的新散列并检查它是否等于存储的散列。
回答by Bjoern
Hashing ain't encrypting.
散列不是加密。
A hash function like MD5 and SHA1 can't be reversed, it only can be verifyed. That is usually the point for using a hash function, because the attacker cannot retrieve the clear passwords with the hashes (other attacks, like using rainbow-tables are ofc possible).
像 MD5 和 SHA1 这样的散列函数无法反转,只能验证。这通常是使用散列函数的重点,因为攻击者无法使用散列检索清晰的密码(其他攻击,如使用彩虹表也是可能的)。
More details can be found here: http://en.wikipedia.org/wiki/Cryptographic_hash_function
更多细节可以在这里找到:http: //en.wikipedia.org/wiki/Cryptographic_hash_function
If you want to store hashed passwords in databases, take a look at PHPass. It is a good class for php to hash and verify passwords as good as currently possible and is widely used in modern php based web applications.
如果您想在数据库中存储散列密码,请查看PHPass。它是 php 的一个很好的类,可以尽可能好地散列和验证密码,并广泛用于现代基于 php 的 Web 应用程序。
回答by Naveen Gamage
Why are you even encrypting them if you eventually want them back? Hashing is used precisely for the reason of being UNABLE to get passwords back in plaintext.
如果你最终想要它们回来,你为什么还要加密它们?使用散列正是因为无法以明文形式获取密码。
Use a symmetric cypher if you want them back.
如果您想要它们回来,请使用对称密码。

