title: PHP: Options to generate an unique user key
body: <p>After a few days researching on hashing, generating random numbers or unique keys, I am a bit confusing now.</p>
  
  <p>I have one last thing that I want to get it right which is the user key. I want to store an unique key for each member/ user who registers at my website. So this key must be unique and not duplicate. I am thinking to use the user email and hash it with timedate or something...</p>
  
  <p>Then I wonder which is the best way to create such a key -</p>
  
  <p><strong>Can I use <a href="http://php.net/manual/en/function.hash-hmac.php" rel="nofollow noreferrer">hash_hmac()</a> to do this for me?</strong></p>
  
  <p>I have a couple of things don't understand about <a href="http://php.net/manual/en/function.hash-hmac.php" rel="nofollow noreferrer">hash_hmac()</a> though - as in this example from the php.net <code>hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');</code></p>
  
  <p>So what is 'secret' - can I put anything different instead, like a timedate?
  I assume that I can replace 'The quick brown fox jumped over the lazy dog.' with the email address?</p>
  
  <p><strong>or maybe I can use <a href="http://www.openwall.com/phpass/" rel="nofollow noreferrer">Portable PHP password hashing framework</a> to do this?</strong></p>
  
  <p>the only thing is that it produces <code>.</code>, <code>$</code>, and <code>/</code> which I need to remove them otherwise I will get errors when I request the key from the URL.</p>
  
  <p>so I might do this - </p>
  
  <pre><code>$hash = $phpass -&gt; HashPassword('me@example.com'.$timedate)
  $key = preg_replace("/[^a-zA-Z0-9]+/", "", $hash);
  </code></pre>
  
  <p>Please let me know if you have any better suggestions.</p>