mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-31 20:47:37 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 37983bf675 | |||
| 1a941f0c86 | |||
| c6f1f47481 | |||
| 3407c33775 | |||
| 401fc07652 | |||
| b5cd72a00a |
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.4
|
|
||||||
- 5.5
|
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
- 7.1
|
- 7.1
|
||||||
- 7.2
|
- 7.2
|
||||||
|
- 7.3
|
||||||
|
- 7.4
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer install
|
- composer install
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedi
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* Tested on PHP 5.4 up to 7.2
|
* Tested on PHP 5.6 up to 7.4
|
||||||
* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `ImageChartsQRCodeProvider` (default), `QRServerProvider` or `QRicketProvider` but you can also provide your own QR-code provider.
|
* [cURL](http://php.net/manual/en/book.curl.php) when using the provided `ImageChartsQRCodeProvider` (default), `QRServerProvider` or `QRicketProvider` but you can also provide your own QR-code provider.
|
||||||
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [MCrypt](http://php.net/manual/en/book.mcrypt.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.
|
* [random_bytes()](http://php.net/manual/en/function.random-bytes.php), [MCrypt](http://php.net/manual/en/book.mcrypt.php), [OpenSSL](http://php.net/manual/en/book.openssl.php) or [Hash](http://php.net/manual/en/book.hash.php) depending on which built-in RNG you use (TwoFactorAuth will try to 'autodetect' and use the best available); however: feel free to provide your own (CS)RNG.
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ Another set of providers in this library are the Time Providers; this library pr
|
|||||||
|
|
||||||
You can easily implement your own `TimeProvider` by simply implementing the `ITimeProvider` interface.
|
You can easily implement your own `TimeProvider` by simply implementing the `ITimeProvider` interface.
|
||||||
|
|
||||||
As to *why* these Time Providers are implemented: it allows the TwoFactorAuth library to ensure the hosts time is correct (or rather: within a margin). You can use the `ensureCorrectTime()` method to ensure the hosts time is correct. By default this method will compare the hosts time (returned by calling `time()` on the `LocalMachineTimeProvider`) to Google's and convert-unix-time.com's current time. You can pass an array of `ITimeProvider`s and specify the `leniency` (second argument) allowed (default: 5 seconds). The method will throw when the TwoFactorAuth's timeprovider (which can be any `ITimeProvider`, see constructor) differs more than the given amount of seconds from any of the given `ITimeProviders`. We advise to call this method sparingly when relying on 3rd parties (which both the `HttpTimeProvider` and `NTPTimeProvider` do) or, if you need to ensure time is correct on a (very) regular basis to implement an `ITimeProvider` that is more efficient than the 'built-in' ones (like use a GPS signal). The `ensureCorrectTime()` method is mostly to be used to make sure the server is configured correctly.
|
As to *why* these Time Providers are implemented: it allows the TwoFactorAuth library to ensure the hosts time is correct (or rather: within a margin). You can use the `ensureCorrectTime()` method to ensure the hosts time is correct. By default this method will compare the hosts time (returned by calling `time()` on the `LocalMachineTimeProvider`) to the default `NTPTimeProvider` and `HttpTimeProvider`. You can pass an array of `ITimeProvider`s to change this and specify the `leniency` (second argument) allowed (default: 5 seconds). The method will throw when the TwoFactorAuth's timeprovider (which can be any `ITimeProvider`, see constructor) differs more than the given amount of seconds from any of the given `ITimeProviders`. We advise to call this method sparingly when relying on 3rd parties (which both the `HttpTimeProvider` and `NTPTimeProvider` do) or, if you need to ensure time is correct on a (very) regular basis to implement an `ITimeProvider` that is more efficient than the 'built-in' ones (like use a GPS signal). The `ensureCorrectTime()` method is mostly to be used to make sure the server is configured correctly.
|
||||||
|
|
||||||
## Integrations
|
## Integrations
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "robthree/twofactorauth",
|
"name": "robthree/twofactorauth",
|
||||||
"description": "Two Factor Authentication",
|
"description": "Two Factor Authentication",
|
||||||
"version": "1.6.6",
|
"version": "1.7.0",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"keywords": [ "Authentication", "Two Factor Authentication", "Multi Factor Authentication", "TFA", "MFA", "PHP", "Authenticator", "Authy" ],
|
"keywords": [ "Authentication", "Two Factor Authentication", "Multi Factor Authentication", "TFA", "MFA", "PHP", "Authenticator", "Authy" ],
|
||||||
"homepage": "https://github.com/RobThree/TwoFactorAuth",
|
"homepage": "https://github.com/RobThree/TwoFactorAuth",
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"source": "https://github.com/RobThree/TwoFactorAuth"
|
"source": "https://github.com/RobThree/TwoFactorAuth"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "@stable"
|
"phpunit/phpunit": "@stable"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class NTPTimeProvider implements ITimeProvider
|
|||||||
public $port;
|
public $port;
|
||||||
public $timeout;
|
public $timeout;
|
||||||
|
|
||||||
function __construct($host = 'pool.ntp.org', $port = 123, $timeout = 1)
|
function __construct($host = 'time.google.com', $port = 123, $timeout = 1)
|
||||||
{
|
{
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
|
||||||
@@ -28,6 +28,7 @@ class NTPTimeProvider implements ITimeProvider
|
|||||||
try {
|
try {
|
||||||
/* Create a socket and connect to NTP server */
|
/* Create a socket and connect to NTP server */
|
||||||
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||||
|
socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, ['sec' => $this->timeout, 'usec' => 0]);
|
||||||
socket_connect($sock, $this->host, $this->port);
|
socket_connect($sock, $this->host, $this->port);
|
||||||
|
|
||||||
/* Send request */
|
/* Send request */
|
||||||
@@ -35,7 +36,8 @@ class NTPTimeProvider implements ITimeProvider
|
|||||||
socket_send($sock, $msg, strlen($msg), 0);
|
socket_send($sock, $msg, strlen($msg), 0);
|
||||||
|
|
||||||
/* Receive response and close socket */
|
/* Receive response and close socket */
|
||||||
socket_recv($sock, $recv, 48, MSG_WAITALL);
|
if (socket_recv($sock, $recv, 48, MSG_WAITALL) === false)
|
||||||
|
throw new \Exception(socket_strerror(socket_last_error($sock)));
|
||||||
socket_close($sock);
|
socket_close($sock);
|
||||||
|
|
||||||
/* Interpret response */
|
/* Interpret response */
|
||||||
@@ -49,4 +51,4 @@ class NTPTimeProvider implements ITimeProvider
|
|||||||
throw new \TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->host, $ex->getMessage()));
|
throw new \TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->host, $ex->getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ class TwoFactorAuth
|
|||||||
{
|
{
|
||||||
// Set default QR Code provider if none was specified
|
// Set default QR Code provider if none was specified
|
||||||
if (null === $this->qrcodeprovider) {
|
if (null === $this->qrcodeprovider) {
|
||||||
return $this->qrcodeprovider = new Providers\Qr\ImageChartsQRCodeProvider();
|
return $this->qrcodeprovider = new Providers\Qr\QRServerProvider();
|
||||||
}
|
}
|
||||||
return $this->qrcodeprovider;
|
return $this->qrcodeprovider;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user