md5(uniqid) makes sense for random unique tokens?

前端 未结 8 924
半阙折子戏
半阙折子戏 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:10

    MD5 is a decent algorithm for producing data dependent IDs. But in case you have more than one item which has the same bitstream (content), you will be producing two similar MD5 "ids".

    So if you are just applying it to a rand() function, which is guaranteed not to create the same number twice, you are quite safe.

    But for a stronger distribution of keys, I'd personally use SHA1 or SHAx etc'... but you will still have the problem of similar data leads to similar keys.

提交回复
热议问题