After a few days researching on hashing, generating random numbers or unique keys, I am a bit confusing now.
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…
Then I wonder which is the best way to create such a key –
Can I use hash_hmac() to do this for me?
I have a couple of things don’t understand about hash_hmac() though – as in this example from the php.net hash_hmac('ripemd160', 'The quick brown fox jumped over the lazy dog.', 'secret');
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?
or maybe I can use Portable PHP password hashing framework to do this?
the only thing is that it produces ., $, and / which I need to remove them otherwise I will get errors when I request the key from the URL.
so I might do this –
$hash = $phpass -> HashPassword('me@example.com'.$timedate)
$key = preg_replace("/[^a-zA-Z0-9]+/", "", $hash);
Please let me know if you have any better suggestions.
md5(uniqid(rand(), TRUE));index.php:
output:
They are all unique and you can just use them. You should NOT have to do anything else?