Answers:
除了以星号开头的密码外,这是PASSWORD()的算法
SET @plaintextpassword = 'whatever password you want';
SELECT CONCAT('*',UPPER(SHA1(UNHEX(SHA1(@plaintextpassword)))));
mysql> SET @plaintextpassword = 'whatever password you want';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT UPPER(SHA1(UNHEX(SHA1(@plaintextpassword)))) PWD_CREATION;
+------------------------------------------+
| PWD_CREATION |
+------------------------------------------+
| D09AF2704D843A5E4E84362830C7EC1CEA40DF8A |
+------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT PASSWORD(@plaintextpassword) PWD_FUNCTION;
+-------------------------------------------+
| PWD_FUNCTION |
+-------------------------------------------+
| *D09AF2704D843A5E4E84362830C7EC1CEA40DF8A |
+-------------------------------------------+
1 row in set (0.00 sec)
mysql>
我很早以前从MySQL PASSWORD()中的哈希算法中学到了该算法
这是mysql 4.1中引入的一项更改,因此可以同时支持16个字符的较早密码长度和40个字符的较新密码长度。“密码”列的长度为41个字节(字符),并且较新的密码将以强制性的开头*
来标识它们。
从文档中:
4.1格式的密码哈希始终以“ *”字符开头,而4.1之前的格式则永远不会。