Forum Moderators: coopster
You need to use salts for storing passwords in cookies.cookie: md5(password . salt)
login: md5(password . <get salt from database>)The end user never knows what their salt is. And if a cracker get's hold of the md5(pass.salt) hash, then they can't crack it because logging in with a cracked md5(pass.salt) (which would be nonsense) would not allow them to log in, because that would be like trying to log in with md5(md5(pass.salt) . salt) which would obviously not match any database records.
[edited by: coopster at 1:41 am (utc) on June 28, 2006]
[edit reason] removed url [/edit]
The 'salt' is random string appended to the end of the password before encryption.
For example if you added a random string to the end of the password and encrypt it, like so:
md5("test" . "5ges")
25136ab23919df5c2ebad1445eb03a66
md5("test5ges" . "5ges")
1d2a83e6bf9037e8902c0c7fadbf34c3
Andrew
There's an interesting idea here [uk.php.net] regarding time sensative hashes. i.e. it will not be valid after N seconds.
Andrew
For example (using fake code for illustration):
When a user chooses their password, for instance, how do you guarantee that none of the other users in that database have the same encrypted 'hash' in the database?
md5(userPWD.fromForm) won't provide that desired uniqueness, because md5('password') will always result in the same 'hashed' value ("5f4dcc3b5aa765d61d8327deb882cf99"). So we add a little 'salt' to the mix.
md5(userPWD.fromForm + userID.fromDatabase) provides a unique bit of text (the user's unique ID) that is appended to the possibly-duplicate password string chosen by the user to make a unique combination. This guarantees a unique 'hash' to be stored in the database for comparison. md5('password'.'24') results in a 'hash' value of "58bad6b697dff48f4927941962f23e90" and md5('password'.'457') results in a 'hash' value of "645296bd2aca27d3bcfa2e3abbc06082". Now, a non-unique password is stored as a unique 'hash' when a 'salt' has been added to the mix. It's a security thing ... you don't want a password cracker with access to the database to be able to figure out a common password by guessing 'hash' values of common passwords.
<edit>WOW! A flurry of answers! :)</edit>