Skip to content

Commit

Permalink
Add more random sources
Browse files Browse the repository at this point in the history
Added support for PHP 7 random_bytes() and the mcrypt package.

Re #2567

Picked from 5a61bf5
  • Loading branch information
nitriques committed Jun 16, 2017
1 parent b0f9adf commit 0b2fdde
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion symphony/lib/toolkit/class.xsrf.php
Expand Up @@ -72,8 +72,18 @@ public static function generateNonce($length = 30)
throw new Exception('$length must be greater than 0');
}

// Use the new PHP 7 random_bytes call, if available
if (function_exists('random_bytes')) {
$random = random_bytes($length);
}

// Try mcrypt package, if available
else if (function_exists('mcrypt_create_iv')) {
$random = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}

// Get some random binary data from open ssl, if available
if (function_exists('openssl_random_pseudo_bytes')) {
else if (function_exists('openssl_random_pseudo_bytes')) {
$random = openssl_random_pseudo_bytes($length);
}

Expand Down

0 comments on commit 0b2fdde

Please sign in to comment.