代码之家  ›  专栏  ›  技术社区  ›  andilabs

django TokenAuthentication在authtoken_token表中始终是唯一的密钥?

  •  1
  • andilabs  · 技术社区  · 12 年前

    我正在使用:

    http://www.django-rest-framework.org/api-guide/authentication#tokenauthentication
    

    在我的设计中,这个问题至关重要:

    django TokenAuthentication is key always unique inside the authtoken_token table
    

    我看过mysql中的数据库表。看来它应该是独一无二的。如果我错了,请纠正我。

    enter image description here

    1 回复  |  直到 12 年前
        1
  •  1
  •   Alexander Meesters    12 年前

    它应该是唯一的是, 如你所见 here 它使用 os.urandom 包裹在里面 binascii.hexlify 这又随机提供40个字符,这应该足以防止冲突。

    但是,如果您想绝对确定,请将用户id与url中的令牌结合起来,因为user_id在数据库中被标记为唯一的,您可以放心地确保不存在双重。