How random is the random string function? |
[eluser]ShoeLace1291[/eluser]
I use the random string function to generate activation codes for my members' accounts. What are the chances that this function will generate the same string twice?
[eluser]LuckyFella73[/eluser]
There are different functions in PHP generating random results. Which one do you use? I would prefer the "mt_rand()" function over "rand()". http://php.net/manual/de/function.mt-rand.php
[eluser]boltsabre[/eluser]
If you are really worried about this, and it is absolutely critical that activation codes are unique can also append/prepend a unix timestamp to your random string when you create it, virtually impossible for duplication if your random string in 10+ characters.
[eluser]niki_mihaylov[/eluser]
Just use user ID from the database - this way there is no chance of getting same code twice. Also you can add timestamp if generating more codes for same user in future. Then you can Md5 or use other sexy function to serve it
|
Welcome Guest, Not a member yet? Register Sign In |