fof/src/eef08a1d-5367-4464-8d07-d47c479fb76f/code.power
2023-10-09 11:38:00 +02:00

37 lines
1.5 KiB
Plaintext

/**
* Returns a cryptographically secure random value.
*
* Since we only run on PHP 7+ we can use random_bytes(), which internally uses a crypto safe PRNG. If the function
* doesn't exist, Joomla already loads a secure polyfill.
*
* The reason this method exists is backwards compatibility with older versions of FOF. It also allows us to quickly
* address any future issues if Joomla drops the polyfill or otherwise find problems with PHP's random_bytes() on
* some weird host (you can't be too careful when releasing mass-distributed software).
*
* @param integer $bytes How many bytes to return
*
* @return string
*/
public function generate($bytes = 32)
{
return random_bytes($bytes);
}
/**
* Generate random bytes. Adapted from Joomla! 3.2.
*
* Since we only run on PHP 7+ we can use random_bytes(), which internally uses a crypto safe PRNG. If the function
* doesn't exist, Joomla already loads a secure polyfill.
*
* The reason this method exists is backwards compatibility with older versions of FOF. It also allows us to quickly
* address any future issues if Joomla drops the polyfill or otherwise find problems with PHP's random_bytes() on
* some weird host (you can't be too careful when releasing mass-distributed software).
*
* @param integer $length Length of the random data to generate
*
* @return string Random binary data
*/
public function genRandomBytes($length = 32)
{
return random_bytes($length);
}