Use PHP7 function random_bytes() to generate tokens if available
This commit is contained in:
@@ -8,6 +8,7 @@ New features:
|
|||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
* Improve error handling of plugins
|
* Improve error handling of plugins
|
||||||
|
* Use PHP7 function random_bytes() to generate tokens if available
|
||||||
|
|
||||||
Internal code refactoring:
|
Internal code refactoring:
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ class Token extends Base
|
|||||||
*/
|
*/
|
||||||
public static function getToken()
|
public static function getToken()
|
||||||
{
|
{
|
||||||
if (function_exists('openssl_random_pseudo_bytes')) {
|
if (function_exists('random_bytes')) {
|
||||||
return bin2hex(\openssl_random_pseudo_bytes(30));
|
return bin2hex(random_bytes(30));
|
||||||
|
} elseif (function_exists('openssl_random_pseudo_bytes')) {
|
||||||
|
return bin2hex(openssl_random_pseudo_bytes(30));
|
||||||
} elseif (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
} elseif (ini_get('open_basedir') === '' && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
|
||||||
return hash('sha256', file_get_contents('/dev/urandom', false, null, 0, 30));
|
return hash('sha256', file_get_contents('/dev/urandom', false, null, 0, 30));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user