md5(uniqid) makes sense for random unique tokens?

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

    This is a copy of another question I found that was asked a few months before this one. Here is a link to the question and my answer: https://stackoverflow.com/a/13733588/1698153.

    I do not agree with the accepted answer. According to PHPs own website "[uniqid] does not generate cryptographically secure tokens, in fact without being passed any additional parameters the return value is little different from microtime(). If you need to generate cryptographically secure tokens use openssl_random_pseudo_bytes()."

    I do not think the answer could be clearer than this, uniqid is not secure.

提交回复
热议问题