MySQL Hashing Function Implementation

前端 未结 7 1655
[愿得一人]
[愿得一人] 2020-12-05 03:31

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

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-05 04:05

    Based on the PHP implementation above, here's a Perl example that works.

    use Digest::SHA1 qw(sha1 sha1_hex);
    sub password { "*".uc(sha1_hex(sha1($_[0]))) }
    

    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.

提交回复
热议问题