Solved

Crypting cooking information!

Posted on 2004-08-31
8
257 Views
Last Modified: 2013-12-12
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!
0
Comment
Question by:Xtry
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 4

Expert Comment

by:llcooljayce
Comment Utility
Hi Xtry,

Try using md5() instead of crypt

Cheers!
0
 

Author Comment

by:Xtry
Comment Utility
is md5 1 way encryption?
0
 
LVL 4

Assisted Solution

by:llcooljayce
llcooljayce earned 50 total points
Comment Utility
I believe so.  You can go to www.php.net/md5 to find out how to impliment it
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 200 total points
Comment Utility
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.

http://www.php.net/manual/en/function.base64-encode.php
http://www.php.net/manual/en/function.base64-decode.php
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Assisted Solution

by:frugle
frugle earned 250 total points
Comment Utility
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.

Mike
0
 
LVL 27

Expert Comment

by:Diablo84
Comment Utility
@ 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.

0
 

Author Comment

by:Xtry
Comment Utility
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';
0
 
LVL 10

Assisted Solution

by:frugle
frugle earned 250 total points
Comment Utility
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.

Mike
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now