security - Secure random number generation in PHP -
Use the case: "I forgot my password" button, we can not get the user's original password as it is in the hashed form Is stored, so only a new random password has been generated and the e-mail has been sent. For this, cryptographically unexpected random numbers are required, for which mt_rand is not enough, and generally we can not consider hosting as a service, providing access to the operating system to install cryptographic random number modules etc. So I'm looking for a way to generate safe random numbers in PHP.
With the solution so far, I have stored an initial seed, then for each call,
result = seed seed = sha 512 (seed MTR)
This shaw is based on the security of the hash function (MT_Rand call is only for an opponent to make life a bit more difficult to achieve.
< / P>
You may also consider using OpenSSL openssl_random_pseudo_bytes, after PHP 5.3 Is available.
string openssl_random_pseudo_bytes (int $ length [, bool & amp; $ crypto_strong])
A string of proxy random bytes Generates the length, with the number of bytes determined by the length parameter. It also indicates that cryptographic algorithms were used to produce pseudo-random bytes, and this is done through optional crypto_strong parameters. It's wrong for What are some systems that can be broken or old.
random_bytes
function is also availablestring by random_bytes (int $ length)
Comments
Post a Comment