MySQL MD5 选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4844717/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:35:56  来源:igfitidea点击:

MySQL MD5 SELECT

mysqlmd5

提问by Isis

This following query returned null.

以下查询返回 null。

SELECT `email`, `password`, `salt` FROM `users` WHERE `password` = md5(`salt`+md5('123123'+`salt`)+'123123') AND `email` = '[email protected]'

The following query returned 'd2b4312db21705dafd96df14f8525fef', but why?

以下查询返回“d2b4312db21705dafd96df14f8525fef”,但为什么呢?

SELECT md5( 'Vwm' + md5( '123123' + 'Vwm' ) + '123123' )  

This code returned '422ad0c19a38ea88f4db5e1fecaaa920'.

此代码返回“422ad0c19a38ea88f4db5e1fecaaa920”。

$salt = 'Vwm';
$password = '123123';

echo md5($salt . md5($password . $salt) . $password);

Do user authorization. How do I create a query to the database so that the first took SALT and SALT have this I did some MD5 function?

做用户授权。如何创建对数据库的查询,以便第一个使用 SALT 和 SALT 我做了一些 MD5 函数?

回答by Ass3mbler

SELECT md5(CONCAT('Vwm', md5(CONCAT('123123', 'Vwm' )), '123123' )) ;

You need to concat() the strings then execute md5() on them.

您需要 concat() 字符串,然后对它们执行 md5()。

This way it returns correctly the same value as your PHP script:

这样它会正确返回与您的 PHP 脚本相同的值:

+--------------------------------------------------------------+
| md5(CONCAT('Vwm', md5(CONCAT('123123', 'Vwm' )), '123123' )) |
+--------------------------------------------------------------+
| 422ad0c19a38ea88f4db5e1fecaaa920                             |
+--------------------------------------------------------------+

回答by Marc B

String concatenation in MySQL requires using CONCAT()`. This;

MySQL 中的字符串连接需要使用 CONCAT()`。这个;

md5( '123123' + 'Vwm' )

is actually adding a number to a string:

实际上是在字符串中添加一个数字:

mysql> select '12123' + 'Vwm';
+-----------------+
| '12123' + 'Vwm' |
+-----------------+
|           12123 |
+-----------------+

So your query is not the same as the PHP side, as you're not hashing the same string.

所以您的查询与 PHP 端不同,因为您没有对相同的字符串进行散列。

回答by bensiu

  • salt should be in your script
  • salted password in your database
  • your script is salting password and compare with salted version in db
  • if same consider OK
  • 盐应该在你的脚本中
  • 数据库中的盐渍密码
  • 您的脚本正在加盐密码并与数据库中的加盐版本进行比较
  • 如果同样考虑好