开发者

Django: Creating a unique identifier for a user based on request.META values

I'm looking at creating an anonymous poll. However, I want to prevent users from voting twice. I was thinking of hashing some r开发者_运维技巧equest.META values like so:

from hashlib import md5

request_id_keys = (
    'HTTP_ACCEPT_CHARSET',
    'HTTP_ACCEPT',
    'HTTP_ACCEPT_ENCODING',
    'HTTP_ACCEPT_LANGUAGE',
    'HTTP_CONNECTION',
    'HTTP_USER_AGENT',
    'REMOTE_ADDR',
)

request_id = md5('|'.join([request.META.get(k, '') for k in requst_id_keys])).hexdigest()

My questions:

  1. Good idea? Bad idea? Why?
  2. Are some of these keys redundant or just overkill? Why?
  3. Are some of these easily changeable? For example, I'm considering removing HTTP_USER_AGENT because I know that's just a simple config change.
  4. Know of a better way of accomplishing this semi-unique identifier that is flexible enough to handle people sharing IP's (NAT) but that a simple config change won't create a new hash?


All of this params are fairly easy to change. Why not just use a cookie for that purpose? I guess something like evercookie

evercookie is a javascript API available that produces extremely persistent cookies in a browser. Its goal is to identify a client even after they've removed standard cookies, Flash cookies (Local Shared Objects or LSOs), and others.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜