Possible Duplicate:
Secure random number generation in PHP
We need to generate a cryptographically random string to use as an authentication token, which will be tied to session data in the database. We are using PHP, which doesn't appear to have a suitable random number generator built-in. How can we generate a cryptographically secure random string of N length using php?
Also note, due to the nature of our application, shell_exec is off the table.
what about
uniqid
? docs have an example of how it can be used for cookies/sessions.Depending on your platform, you may use /dev/urandom or CAPICOM. This is nicely summarized in this comment from Mark Seecof:
Off the top of my head: take micro time, multiply it by microtime % 100 and do few randoms on sha1 of received result.