md5(uniqid) makes sense for random unique tokens?

前端 未结 8 920
半阙折子戏
半阙折子戏 2020-12-12 17:12

I want to create a token generator that generates tokens that cannot be guessed by the user and that are still unique (to be used for password resets and confirmation codes)

8条回答
  •  半阙折子戏
    2020-12-12 18:12

    To answer your question, the problem is you can't have a generator that is guaranteed random and unique as random by itself, i.e., md5(mt_rand()) can lead to duplicates. What you want is "random appearing" unique values. uniqid gives the unique id, rand() affixes a random number making it even harder to guess, md5 masks the result to make it yet even harder to guess. Nothing is unguessable. We just need to make it so hard that they wouldn't even want to try.

提交回复
热议问题