Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, it seems that you are using plain <code>md5()</code> to store user passwords... <strong>DO NOT DO THAT, IT IS A <i>SECURITY RISK</i>.</strong> <i>You are putting your users and yourself at risk.</i> Use key strengthening with a stronger hash algorithm or bcrypt. <a href="https://stackoverflow.com/questions/6340105/how-can-we-create-a-fairly-secure-password-hash-in-php/6340197#6340197">See this answer for more information</a>.</p> <hr> <p>It seems that you are actually trying to generate a <code>nonce</code> for email activation.</p> <p>If anything, a <a href="http://en.wikipedia.org/wiki/UUID" rel="nofollow noreferrer">Universally Unique IDentifier (UUID)</a> will do the job. It has a very low change of collision and allows for 3 × 10<sup>38</sup> unique values (once a value is used, you can reuse it for another user anyway for your use case).</p> <p>You can use this function I wrote to generate UUIDs in PHP. What you want for your needs is a v4 UUID.</p> <pre><code>function UUIDv4() { $bytes = str_split(crypto_random_bytes(16)); // Set UUID Version Number $bytes[6] = $bytes[6] &amp; "\x0f" | "\x40"; // Set UUID DCE1.1 varient $bytes[8] = $bytes[8] &amp; "\x3f" | "\x80"; $uuid = bin2hex(implode($bytes)); return sprintf('%08s-%04s-%04s-%04s-%12s', // 32 bits for "time_low" substr($uuid, 0, 8), // 16 bits for "time_mid" substr($uuid, 8, 4), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 substr($uuid, 12, 4), // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 substr($uuid, 16, 4), // 48 bits for "node" substr($uuid, 20, 12) ); } function crypto_random_bytes($count) { static $randomState = null; $bytes = ''; if(function_exists('openssl_random_pseudo_bytes') &amp;&amp; (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win $bytes = openssl_random_pseudo_bytes($count); } if($bytes === '' &amp;&amp; is_readable('/dev/urandom') &amp;&amp; ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) { $bytes = fread($hRand, $count); fclose($hRand); } if(strlen($bytes) &lt; $count) { $bytes = ''; if($randomState === null) { $randomState = microtime(); if(function_exists('getmypid')) { $randomState .= getmypid(); } } for($i = 0; $i &lt; $count; $i += 16) { $randomState = md5(microtime() . $randomState); if (PHP_VERSION &gt;= '5') { $bytes .= md5($randomState, true); } else { $bytes .= pack('H*', md5($randomState)); } } $bytes = substr($bytes, 0, $count); } return $bytes; } </code></pre>
 

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