Jump to content

MySQL PASSWORD() for encryption


Recommended Posts

Hi to all!


I want to ask you that, what are the advantages and disadvantages of using MySQL PASSWORD() function to encrypt the sensitive data in database.

Should i opt for MySQL PASSWORD() function or PHP md5() function, please suggest me?

Link to comment
Share on other sites

md5() should be used instead of password() to encrypt data, from mysql documentation:


Note: The PASSWORD() function is used by the authentication system in MySQL Server; you should not use it in your own applications. For that purpose, use MD5() or SHA1() instead. Also see RFC 2195 for more information about handling passwords and authentication securely in your applications.

Link to comment
Share on other sites

Thanks for your reply.

I have read MYSQL documentation and they say:

  The encryption and compression functions return binary strings. For many of these functions, the result might contain arbitrary byte values. If you want to store these results, use a BLOB  column rather than a CHAR or VARCHAR column to avoid potential problems with trailing space removal that would change data values.


BLOB column will take unnecessary storage space in database, is there any other option to use CAHR or VARCHAR field to store the data.

Link to comment
Share on other sites

I have never had a problem using a varchar column for encrypted data, besides BLOB holds a variable amount of data anyway or use VARBINARY instead.

Just be careful about the maximum length, certain encryption functions are block-based.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.