Jump to content

How do I encrypt and decrypt?

Recommended Posts


I'd just like to enquire, what is the best way to encrypt and decrypt please?

I've created a basic signup form, and I would like to encrypt the data before it's written to a database.

Then when I come to create the log in screen, I would like to access the database, pull a record, then decrypt the email and password, to check it matches what the user has entered.

Or is there an easier way?


Thank You.


ps. Also could I please just ask.  I've created a function for something else.  When I've finished with it, can I delete or destroy it?


Share this post

Link to post
Share on other sites

There are a few encryption libraries to help with that task, although many of them may require dependencies like OpenSSL to be installed.

Although, why do you want to encrypt everything in the database?  If you encrypt the email address, how will you look up the user?  Are you saying you'll encrypt the email address they enter, and then search for the encrypted text in the database?  That will make your system case-sensitive if you do that.  

Also, I would strongly recommend not encrypting passwords, the only reason to do that is if you want to be able to email someone their password, but that's also not the best idea.  For storing passwords you should salt and hash them.  PHP has the password_hash and password_verify functions for that.

Share this post

Link to post
Share on other sites

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.   Paste as plain text instead

  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...