views:

256

answers:

2

I am thinking that I create a deactivation code put that in the unsubscribe link along with their user id. Then when a recipient of my newsletter clicks the link, I can look up their user id and see if the deactivation code matches.

Does this sound like the best way?

What are some other ways?

+3  A: 

From a user perspective, do not require the user to input the e-mail address to unsubscribe. An approach that has all the information embedded in the link (such as you describe) is much better.

g .
+4  A: 

You could just use an hashing algorithm to secure the userID (so that nobody can unregister all your DB with a nasty loop).

You'll end up with two params : userID and hash.

The advantage is that you won't need to store any mapping between deactivation code and userID.

MatthieuP
Let me get this straight... the userID param in this case would be hashed with the hash param. So the params are userID and hash, and then hash(hashedUserID,hash) = userID ....correct?
Tony
Chase Seibert
Then I have to keep the secret in the database which would essentially be the deactivation code. So what's the advantage?
Tony
No database involved, because you'll have only one secret for all your application. The secret will only appear (once) in your code.
MatthieuP