Reputation: 13555
I am doing some kind of unsubscribe page.
My idea is using the get method with encryption. for example:
unsubscribe.php?mail=xxxxxxxxxxxxxxxx&uid=xxxxxxxxxxxxxxxxxx
It can automatically unsubscibe the receiver once he click the link.
I am going to encrypt the data using sha1 so the problem is
1) is it secure? 2) Whether i have to make a extra 2 field for the encrypted uid and mail address?
Thank you
Upvotes: 2
Views: 1589
Reputation: 165271
Absolultely not!
Do not encrypt the user's data like that. You're doing nothing but needlessly exposing user data to the public.
Besides hashing is not encryption...
Instead, create a long random string (at least 40 characters), and store it in the database for that user. Then add that to the mail unsubscribe link. That way, there's no chance of data leakage...
To generate the random string, you can use a function similar to this:
function makeRandomString($bytes) {
$seed = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$len = strlen($seed) - 1;
$return = '';
for ($i = 0; $i < $bytes; $i++) {
$return .= $seed[mt_rand(0, $len)];
}
return $return;
}
$random = makeRandomString(40); // 40 character random string...
Upvotes: 4
Reputation: 449733
Don't encrypt - create a random key instead, which you store in your database and retrieve when the user arrives at the unsubscribe link! Much easier and safer.
email | random_key
-------------------------------
[email protected] | dsadfdsfsaf2
[email protected]| dfssf32e34fa
the unsubscribe link:
unsubscribe.php?key=dfssf32e34fa <---- [email protected]
Upvotes: 5