I am slowly moving my (unreleased) CMS from $_SESSION
to $_COOKIE
. Content on the internet seems to be biased more towards $_SESSION
(I assume because ease of use). I am looking for security tips on saving cookies. Currently, I am storing (somewhat similar WordPress) a cookie in the format:
'logged_in_%hash_key%' => "username | %hash_password%"
Where my %hash_key%
is md5(MYSALT."something".UNIQUE_KEY)
and UNIQUE_KEY
is regenerated (if the user chooses) after each login to lock out other computers that might have a cookie stored. It is a random 6-character string.
%hash_password%
is similarly generated with Salt and random key (hashed).
I must know the key of the $_COOKIE
(obviously), then I split the string by "|" and look at the username and password. If something doesn't match, I destroy the cookies.
My question is: do you have any other tips on storing cookies in a secure format, or is this good?
I also generate a nonce for each requested action. For example, I create a nonce for 'delete' and I expect to get that nonce back in my $_REQUEST
. I don't log the user out if I get an incorrect response, but I don't do anything.
As meagar pointed out, I know COOKIES are inherently unsafe, I am still trying to do my best to make it all secure.