⌘BABAKOV.NET Let's code!
100% [light] [ru]

Functions of Irreversible Encryption in MySQL (MD5, PASSWORD, SHA1)

This publication will consider some functions of irreversible encryption used in the MySQL database management system.


MD5() Function — produces irreversible encryption of incoming data using the MD5 (Message-Digest Algorithm) algorithm.


The function accepts a string as input and returns a 128-bit checksum calculated using the MD5 algorithm. The returned value is a 32-bit hexadecimal number, unique for each string. If the strings differ by at least one character, the result of the MD5() function for these strings will be different, for two identical strings - the result will always be the same.


Examples:

mysql> select md5(\'Roman\'), md5(\'Roman\');
+----------------------------------+----------------------------------+
| md5(\'Roman\')                     | md5(\'Roman\')                     |
+----------------------------------+----------------------------------+
| b5df36ac79aa6391ffb432b9e5ad7880 | b5df36ac79aa6391ffb432b9e5ad7880 |
+----------------------------------+----------------------------------+
1 row in set (0.00 sec)

mysql> select md5(\'Roman V\'), md5(\'Roman\');
+----------------------------------+----------------------------------+
| md5(\'Roman V\')                   | md5(\'Roman\')                     |
+----------------------------------+----------------------------------+
| c8337353085605e2945ad8f94b787dfb | b5df36ac79aa6391ffb432b9e5ad7880 |
+----------------------------------+----------------------------------+
1 row in set (0.00 sec)


PASSWORD() Function — also produces irreversible encryption of data, this function encrypts user passwords in the password column of the user table in the MySQL system database.


Example:

mysql> select password(\'Roman\'), password(\'Roman\');
+-------------------------------------------+-------------------------------------------+
| password(\'Roman\')                         | password(\'Roman\')                         |
+-------------------------------------------+-------------------------------------------+
| *13F80D80FAC1C0A0FB300C8FCE4E39B232433608 | *13F80D80FAC1C0A0FB300C8FCE4E39B232433608 |
+-------------------------------------------+-------------------------------------------+
1 row in set (0.00 sec)

mysql> select password(\'Roman V\'), password(\'Roman\');
+-------------------------------------------+-------------------------------------------+
| password(\'Roman V\')                       | password(\'Roman\')                         |
+-------------------------------------------+-------------------------------------------+
| *6F3290D96EA0CF5D14C521DC4706DA9C37AD67A5 | *13F80D80FAC1C0A0FB300C8FCE4E39B232433608 |
+-------------------------------------------+-------------------------------------------+
1 row in set (0.00 sec)


In old versions of MySQL, a less secure encryption algorithm was used. For compatibility, there is a function OLD_PASSWORD() — implementing the old encryption algorithm.


Example:

mysql> select password(\'Roman\'), old_password(\'Roman\');
+-------------------------------------------+-----------------------+
| password(\'Roman\')                         | old_password(\'Roman\') |
+-------------------------------------------+-----------------------+
| *13F80D80FAC1C0A0FB300C8FCE4E39B232433608 | 797b74f76f364a6d      |
+-------------------------------------------+-----------------------+
1 row in set, 1 warning (0.00 sec)


Since the PASSWORD() function is used in the MySQL identification system, it is better not to use it for personal needs and use the SH1() and MD5() functions instead.


SHA1 Function — calculates a 160-bit checksum using the SHA1 (Secure Hash Algorithm) algorithm.


The returned value is a 40-bit hexadecimal number, or NULL (in the case of a NULL input parameter).


Example:

mysql> select sha1(\'Roman\'), sha1(\'Roman\');
+------------------------------------------+------------------------------------------+
| sha1(\'Roman\')                            | sha1(\'Roman\')                            |
+------------------------------------------+------------------------------------------+
| 396bd07890bc77d98cce08898143095a50e943a4 | 396bd07890bc77d98cce08898143095a50e943a4 |
+------------------------------------------+------------------------------------------+
1 row in set (0.00 sec)

mysql> select sha1(\'Roman V\'), sha1(\'Roman\');
+------------------------------------------+------------------------------------------+
| sha1(\'Roman V\')                          | sha1(\'Roman\')                            |
+------------------------------------------+------------------------------------------+
| 7430a7e8676e3f1a39802dcbbca0e5a8c61ee179 | 396bd07890bc77d98cce08898143095a50e943a4 |
+------------------------------------------+------------------------------------------+
1 row in set (0.00 sec)


That's all.

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.