Crypting cooking information!

Ok this is what I did:
1. Put the $username, Crypt($password) in the cookie file
2. When I read it, I need 2 verify the same password with the one on MySQL database but I see that mysql has no Crypt function!

Is there any other way of doing the same thing that I have mentioned here!
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Diablo84Connect With a Mentor Commented:
Strictly speaking MD5 is a hash (not encryption), it is the most common method of storing passwords in a cookie however as the original value cannot be recovered it depends on the password being stored in the database as an MD5 hash.

So you have two options, one is to update your database with all the passwords as an MD5 hash and then use md5($password) when you store the balue in the cookie. The other is to use an alternative method using base64 to encode the value.

when you set the cookie use base64_encode($password) and when you read from the cookie use base64_decode to retrive the original value. This is not what base64 encoding was designed for however it will work for this purpose and will mean less changes to your system.
Hi Xtry,

Try using md5() instead of crypt

XtryAuthor Commented:
is md5 1 way encryption?
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

llcooljayceConnect With a Mentor Commented:
I believe so.  You can go to to find out how to impliment it
frugleConnect With a Mentor Commented:
Diablo, base64 encoding passwords is a pretty inefficient way to store passwords, as it is easy to spot base64 encoding and most people can decode base64 in their heads.

The correct technique to do is use one-way encryption (crypt or md5) and store the result.

Take the input from the user, encrypt it with the same salt, and compare the resulting string with the stored string.

If the two strings are the same, the password must have been correct.

The benefit of md5 is that both php and mysql can do it.

@ frugle

Agreed with regards to base64, MD5 is the better method but described above it will mean more modification to the system so i was looking towards an easier alternative.

>> most people can decode base64 in their heads

Maybe so for advanced computer literate users but I doubt most computer users have even heard of base64 (refering to the average user)... and for that matter probably wont know that much about cookies. The actual cookie is also restricted to the local machine so its not that easily accessible.

Nonetheless i am not promoting using base64, MD5 should be used but as i said before it means updating the password field in the database rather then just modifying the script.

XtryAuthor Commented:
Cant I just do something like encrypt the password with MD5 and rather than changing all the passwords in the database do this:

SELECT * FROM `userdb` WHERE `username` = '$usernameFromCookie' AND md5(`password`) = '$md5EncryptedPasswordFromCookie';
frugleConnect With a Mentor Commented:
as long as the password in the cookie is the same as the crypted password that's stored in the database, yes.

you could also quickly md5 all your passwords in your database by performing an update query:

update table set `password` = md5(`password`);

WARNING: this operation is unreversible - backup your data first.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.