For several cases I would need to create random md5 hashes. Do you know what the best / most secure ways of doing this are?
Some use cases
- Verifying an email address
- Resetting passwords
- Some kind of session id used for authentication, instead of password (eg: when someone hits "remember me", I would not like to store the pass in a cookie)
Background
I know that rand()
should not be used for security relevant applications. For that reason I went with:
md5( uniqid(mt_rand(),true) );
Now I read in the php manual about uniqid()
, that it must not be used for security purposes. Which kind of makes sense because it usually just gives something like a timestamp.
But is it fine when combined with a random prefix - mt_rand()
- like I do, or is there something better that should be used in this case?
Thx in advance!
base64_encode
php.net/manual/en/function.base64-encode.php to encode. – Tripletopenssl_random_pseudo_bytes()
as alternative. – Infliction