I know that php has md5(), sha1(), and the hash() functions, but I want to create a hash using the MySQL PASSWORD() function. So far, the only way I can think of is to just query the server, but I want a function (preferably in php or Perl) that will do the same thing without querying MySQL at all.
For example:
MySQL hash -> 464bb2cb3cf18b66
MySQL5 hash -> *01D01F5CA7CA8BA771E03F4AC55EC73C11EFA229
Thanks!
Yes, too late but I just came up this implementation on that page: http://dev.mysql.com/doc/refman/5.1/en/password-hashing.html
Here is the equivalent php function to mysql password;
Why do you want to use mysql password() function? Even the Mysql documentation advises against this:
http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_password
You can use md5() for example, wich is present in almost every programming language, php and perl included.
If you are interested in the algorithm of this function, download the source code and see the file sql/password.c, or check this implementation.
I originally stumbled across this question in my own search for a PHP implementation of the two MySQL password hashing functions. I was unable to find any implementations, so I adapted my own from the MySQL source code (sql/password.c). The following are tested and working in PHP 5.2:
Hopefully someone else will find this useful as well :)
Bad boys do that in bash with sha1sum ;)
OT, but anyway... :)
Based on the PHP implementation above, here's a Perl example that works.
The password function returns the same as the MySQL5 PASSWORD() function.
In answer to "why would anyone want to do this?", I use it to generate SQL "CREATE USER" statements that don't contain plain-text passwords.