Unique key generation

后端 未结 13 2217
一个人的身影
一个人的身影 2020-12-03 05:53

I looking for a way, specifically in PHP that I will be guaranteed to always get a unique key.

I have done the following:

strtolower(substr(crypt(tim         


        
13条回答
  •  再見小時候
    2020-12-03 06:19

    I usually do it like this:

    $this->password = '';
    
    for($i=0; $i<10; $i++)
    {
        if($i%2 == 0)
            $this->password .= chr(rand(65,90));
        if($i%3 == 0)
            $this->password .= chr(rand(97,122));
        if($i%4 == 0)
            $this->password .= chr(rand(48,57));
    }
    

    I suppose there are some theoretical holes but I've never had an issue with duplication. I usually use it for temporary passwords (like after a password reset) and it works well enough for that.

提交回复
热议问题