Using encrypted passwords in mysql

It is a good idea to store passwords in encrypted forms in mysql databases. Function MD5() is a good option to encrypt the passwords. You can use this function in the mysql codes to encrypt the passwords. There may be some situations that we may need to reset the password stored in encrypted form, then also you can use the same MD5() function.

Here is one such situation. One customer sets his password in a table say ‘access’.

—————————————

mysql> select * from access;
+----------+----------------------------------+
| userid | passwd |
+----------+----------------------------------+
| testuser | c03d38cc11d91bb813351fb7985adae9 |
+----------+----------------------------------+
1 row in set (0.01 sec)

—————————————

 

What happens if he forgot that password ?? We have no option to decrypt the password, so what we can do is to reset the password right?. Here it goes..

We can reset the new encrypted password using the command below.

mysql> update access set passwd=MD5('newpassword') where userid='testuser';

this will set the password new password in MD5 encrypted form.

For example if we want to reset the password as ‘redhat’ then just give the command.

-------------------------------------

mysql> update access set passwd=MD5(‘redhat’) where userid=’testuser’;

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> select * from access;
+----------+----------------------------------+
| user | passwd |
+----------+----------------------------------+
| testuser | e2798af12a7a0f4f70b4d69efbc25f4d |
+----------+----------------------------------+
1 row in set (0.00 sec)

-------------------------------------

Here 'e2798af12a7a0f4f70b4d69efbc25f4d' is the MD5 encrypted form of 
redhat.

Both comments and pings are currently closed.

Comments are closed.