Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I like this method of generating a cryptographically secure pseudo-random number generator or (CSPRNG) for PHP. It was <a href="https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string/13733588#13733588">written by Scott</a>:</p> <pre><code>&lt;?php function crypto_rand_secure($min, $max) { $range = $max - $min; if ($range &lt; 0) return $min; // not so random... $log = log($range, 2); $bytes = (int) ($log / 8) + 1; // length in bytes $bits = (int) $log + 1; // length in bits $filter = (int) (1 &lt;&lt; $bits) - 1; // set all lower bits to 1 do { $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes))); $rnd = $rnd &amp; $filter; // discard irrelevant bits } while ($rnd &gt;= $range); return $min + $rnd; } function getToken($length=32){ $token = ""; $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz"; $codeAlphabet.= "0123456789"; for($i=0;$i&lt;$length;$i++){ $token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))]; } return $token; } ?&gt; </code></pre> <p>In terms of adding a timeout, I recommend taking care of this in the database. Add a column that is called like registration_timeout and then use mysql's addtime() function to set this colmn to the current time stamp + however long you want the timeout to be.</p> <p>Also keep in mind that temporary email accounts are trivial to use (<a href="http://www.mailinator.com" rel="nofollow noreferrer">http://www.mailinator.com</a> , <a href="http://www.guerrillamail.com" rel="nofollow noreferrer">http://www.guerrillamail.com</a>, ect...), so asking for someone to register an email account doesn't mean anything. Further more a user account could end up on <a href="http://www.bugmenot.com" rel="nofollow noreferrer">http://www.bugmenot.com</a> . </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload