Encrypt, Decrypt password in Mysql

Some times you need to store encrypted data in the data base, specially for the case of user passwords.

Writing code to retrieve in programming language can be tedious. Mysql functions provide a great deal here.

You can easily encrypt fields when inserting in MySql

INSERT INTO PASSWORD(pass)
VALUES(DES_ENCRYPT(‘user password’));
This SQL will encrypt the user inserted field to a encrypted text.
Instead of DES_ENCRYPT() method you can come up with your own function also.

For retrieval you can use


SELECT DES_DECRYPT(pass) FROM PASSWORD ;
This SQL will return the encrypted text.