Jump to content

How do I encrypt and decrypt?


IChaps

Recommended Posts

Hello.

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?

Thanks.

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...