summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Riesen <chris.riesen@gmail.com>2015-10-08 10:17:59 +0200
committerChristian Riesen <chris.riesen@gmail.com>2015-10-08 10:17:59 +0200
commit20a539ce6280eb029030f4e7caefd5709a75e1ad (patch)
tree836aa56be355b8cebc6f2c0cdcfc47c5746629f9 /src
parent31fda410cbb7ca632552e8f50069be135455da9f (diff)
downloadotp-20a539ce6280eb029030f4e7caefd5709a75e1ad.zip
otp-20a539ce6280eb029030f4e7caefd5709a75e1ad.tar.gz
otp-20a539ce6280eb029030f4e7caefd5709a75e1ad.tar.bz2
Add random_int with polyfill suggestions as default random generator1.4.3
Not a BC. Just will use that first, if present. In PHP7 it's already part of the core, and the polyfill can be installed to take care of the rest. Always will fall back to the current methods. Fixes #8. Thanks to @inanimatt for the suggestion.
Diffstat (limited to 'src')
-rw-r--r--src/Otp/GoogleAuthenticator.php10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Otp/GoogleAuthenticator.php b/src/Otp/GoogleAuthenticator.php
index 9f3db9d..23e67ff 100644
--- a/src/Otp/GoogleAuthenticator.php
+++ b/src/Otp/GoogleAuthenticator.php
@@ -163,9 +163,17 @@ class GoogleAuthenticator
return $string;
}
+ /**
+ * Get random number
+ *
+ * @return int Random number between 0 and 31 (including)
+ */
private static function getRand()
{
- if (function_exists('openssl_random_pseudo_bytes')) {
+ if (function_exists('random_int')) {
+ // Uses either the PHP7 internal function or the polyfill if present
+ return random_int(0, 31);
+ } elseif (function_exists('openssl_random_pseudo_bytes')) {
$bytes = openssl_random_pseudo_bytes(2);
$number = hexdec(bin2hex($bytes));