Skip to content

Commit

Permalink
Use random_bytes() in PHP >=7.0 if available
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPGangsta committed Oct 8, 2016
1 parent c548961 commit 0ad4c4c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions PHPGangsta/GoogleAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public function createSecret($secretLength = 16)
}
$secret = '';
$rnd = false;
if (function_exists('mcrypt_create_iv')) {
if (function_exists('random_bytes')) {
$rnd = random_bytes($secretLength);
} elseif (function_exists('mcrypt_create_iv')) {
$rnd = mcrypt_create_iv($secretLength, MCRYPT_DEV_URANDOM);
}
elseif (function_exists('openssl_random_pseudo_bytes')) {
} elseif (function_exists('openssl_random_pseudo_bytes')) {
$rnd = openssl_random_pseudo_bytes($secretLength, $cryptoStrong);
if (!$cryptoStrong) {
$rnd = false;
Expand Down

0 comments on commit 0ad4c4c

Please sign in to comment.