我猜你把这些电子邮件地址保存在某个地方。因此,为您拥有的每个条目制作一个安全标识符非常容易。无论是散列还是某种加密技术,都无关紧要。但我想哈希更容易实现,实际上是为了这项工作。
因此,您可以散列例如电子邮件地址、记录的 PK 值、添加时间的时间戳,以及一些真的不可能猜到的盐。只需将各个字段连接在一起并散列它们。
最后,您只向服务器发送散列密钥。因此,当您发送这两个链接时,它们可能如下所示:
http://www.url.com/newsletter/acceptsubscription.aspx?id=x1r15ff2svosdf4r2s0f1
http://www.url.com/newsletter/cancelsubscription.aspx?id=x1r15ff2svosdf4r2s0f1
当用户单击此类链接时,您的服务器会在数据库中查找包含所提供密钥的记录。易于实施,如果操作正确,则非常安全。在地狱里没有办法有人可以猜到另一个人的钥匙。在使用散列做某事时,请记住标准的事情。如:
- 不要忘记加盐。
- 选择一个非常慢且非常安全的散列算法。
- 只要确保没有人可以从他们可以拥有的信息中找出他们自己的哈希值。
- If you are really scared of people doing bad things, make sure to stop bruteforcing by adding throttle control to the website. Only allow X number of requests per minute for example. Or some form of banning on an IP-address.
I'm not an expert at these things, so there might be room for improvement. However I think this should point you in the right direction.
edit: I have to add; the solution provided by Tim C is also good. GUID's are indeed very useful for situations like these, and work effectively the same as my hashed solution above.