Can we convert MD5 to SHA256 in a MySQL table with user password column?

MySQLMySQLi Database

Use SHA2() to convert the MD5 password to SHA256. It calculates the SHA-2 family of hash functions i.e. SHA-224, SHA-256, SHA-384, and SHA-512).

Let us first create a table −

mysql> create table DemoTable818(UserPassword text);
Query OK, 0 rows affected (0.51 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable818 values(MD5('John_123'));
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable818 values(MD5('999Carol@22'));
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable818;

This will produce the following output −

+----------------------------------+
| UserPassword                     |
+----------------------------------+
| 47c7d0987db4e59e2264ce9fefce4977 |
| 950aa70edd5b686a807b3bfffdf2248c |
+----------------------------------+
2 rows in set (0.00 sec)

Following is the query to convert MD5 to SHA256 −

mysql> update DemoTable818 set UserPassword=SHA2(UserPassword,256);
Query OK, 2 rows affected (0.19 sec)
Rows matched: 2 Changed: 2 Warnings: 0

Let us check the table records once again −

mysql> select *from DemoTable818;

This will produce the following output −

+------------------------------------------------------------------+
| UserPassword                                                     |
+------------------------------------------------------------------+
| 8b68c46294a9ccb2449324c24fe774f95b7c14e4b56fc51c7f8e6c5b01c7020f |
| 9cc80741546051ae3de7d31246327968c98af3c65125376acb7b49a0760d42a3 |
+------------------------------------------------------------------+
2 rows in set (0.00 sec)
raja
Published on 03-Sep-2019 11:41:35
Advertisements