php MySQL ENCRYPT 密码但如何解密?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16485906/
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
MySQL ENCRYPT password but how to DECRYPT?
提问by senzacionale
I am going through this tutorial and I am using the ENCRYPT MySQL function.
我正在阅读本教程,并且正在使用 ENCRYPT MySQL 函数。
But now I have the problem of how to decrypt the encrypted password in MySQL or in php? I want to compare if the password entered is the same as the encrypted one.
但是现在我遇到了如何在MySQL或php中解密加密密码的问题?我想比较输入的密码是否与加密的相同。
How can I compare it? MySQL must be encrypted with the ENCRYPT function!
我怎样才能比较它?MySQL 必须使用 ENCRYPT 函数加密!
I am searching but I can not find anything how to decrypt the ENCRYPT MySQL function...
我正在搜索,但找不到任何如何解密 ENCRYPT MySQL 函数的信息...
回答by hek2mgl
ENCRYPT
is using a one way hash algorithm there is no DECRYPT
.. That's the sense of enrypting passwords: a hacker should have no option to see the clear text passwords.
ENCRYPT
正在使用一种单向哈希算法,没有DECRYPT
.. 这就是加密密码的意义:黑客不应该选择查看明文密码。
When you need to compare a password in db with one a user has entered, use a query like this (using prepared queries)
当您需要将 db 中的密码与用户输入的密码进行比较时,请使用这样的查询(使用准备好的查询)
SELECT * FROM `user`
WHERE `name` = 'hek2mgl`
AND `password` = ENCRYPT('user_input', `password`)
The ENCRYPT
function will output a "salted" string prefixed with the salt itself, so feeding it back the encrypted password will re-supply the original salt.
该ENCRYPT
函数将输出一个以盐本身为前缀的“salted”字符串,因此将加密密码反馈给它会重新提供原始盐。
回答by RichieHindle
You can't decrypt the password - it is encrypted with one-way encryption.
您无法解密密码 - 它使用单向加密进行加密。
What you need to do is encrypt the entered password and compare the result with the stored encrypted password.
您需要做的是对输入的密码进行加密,并将结果与存储的加密密码进行比较。
回答by Gianluca Ghettini
you don't need to DECRYPT the password. In order to check if a user submitted the correct password, just RE-ENCRYPT the password given by the user and check if it matches the one stored in your database.
您不需要解密密码。为了检查用户是否提交了正确的密码,只需重新加密用户提供的密码并检查它是否与存储在数据库中的密码匹配。
Moreoever, a simple hash function will suffice (avoid MD5 and make use of salt to prevent dictionary or rainbow-tables attacks!)
此外,一个简单的哈希函数就足够了(避免使用 MD5 并使用 salt 来防止字典或彩虹表攻击!)