mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-30 03:57:29 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fca87f2d09 | |||
| 72572c5c3a | |||
| a813bf7ede |
@@ -1,6 +1,6 @@
|
|||||||
#  PHP library for Two Factor Authentication
|
#  PHP library for Two Factor Authentication
|
||||||
|
|
||||||
[](https://travis-ci.org/RobThree/TwoFactorAuth/) [](https://packagist.org/packages/robthree/twofactorauth) [](LICENSE) [](https://packagist.org/packages/robthree/twofactorauth) [](http://hhvm.h4cc.de/package/robthree/twofactorauth) [](https://codeclimate.com/github/RobThree/TwoFactorAuth) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6MB5M2SQLP636 "Keep me off the streets")
|
[](https://travis-ci.org/RobThree/TwoFactorAuth/) [](https://packagist.org/packages/robthree/twofactorauth) [](LICENSE) [](https://packagist.org/packages/robthree/twofactorauth) [](https://codeclimate.com/github/RobThree/TwoFactorAuth) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6MB5M2SQLP636 "Keep me off the streets")
|
||||||
|
|
||||||
PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) using [TOTP](http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm) and [QR-codes](http://en.wikipedia.org/wiki/QR_code). Inspired by, based on but most importantly an *improvement* on '[PHPGangsta/GoogleAuthenticator](https://github.com/PHPGangsta/GoogleAuthenticator)'. There's a [.Net implementation](https://github.com/RobThree/TwoFactorAuth.Net) of this library as well.
|
PHP library for [two-factor (or multi-factor) authentication](http://en.wikipedia.org/wiki/Multi-factor_authentication) using [TOTP](http://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm) and [QR-codes](http://en.wikipedia.org/wiki/QR_code). Inspired by, based on but most importantly an *improvement* on '[PHPGangsta/GoogleAuthenticator](https://github.com/PHPGangsta/GoogleAuthenticator)'. There's a [.Net implementation](https://github.com/RobThree/TwoFactorAuth.Net) of this library as well.
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "robthree/twofactorauth",
|
"name": "robthree/twofactorauth",
|
||||||
"description": "Two Factor Authentication",
|
"description": "Two Factor Authentication",
|
||||||
"version": "1.6.2",
|
"version": "1.6.4",
|
||||||
"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",
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ class TwoFactorAuth
|
|||||||
// To keep safe from timing-attachs we iterate *all* possible codes even though we already may have verified a code is correct
|
// To keep safe from timing-attachs we iterate *all* possible codes even though we already may have verified a code is correct
|
||||||
for ($i = -$discrepancy; $i <= $discrepancy; $i++) {
|
for ($i = -$discrepancy; $i <= $discrepancy; $i++) {
|
||||||
$ts = $timetamp + ($i * $this->period);
|
$ts = $timetamp + ($i * $this->period);
|
||||||
$timeslice += $this->codeEquals($this->getCode($secret, $ts), $code) ? $ts : 0;
|
$slice = $this->getTimeSlice($ts);
|
||||||
|
$timeslice += $this->codeEquals($this->getCode($secret, $ts), $code) ? $slice : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $timeslice > 0;
|
return $timeslice > 0;
|
||||||
|
|||||||
@@ -157,19 +157,19 @@ class TwoFactorAuthTest extends PHPUnit_Framework_TestCase
|
|||||||
// We test with discrepancy 3 (so total of 7 codes: c-3, c-2, c-1, c, c+1, c+2, c+3
|
// We test with discrepancy 3 (so total of 7 codes: c-3, c-2, c-1, c, c+1, c+2, c+3
|
||||||
// Ensure each corresponding timeslice is returned correctly
|
// Ensure each corresponding timeslice is returned correctly
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '534113', 3, 1426847190, $timeslice1));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '534113', 3, 1426847190, $timeslice1));
|
||||||
$this->assertEquals(1426847100, $timeslice1);
|
$this->assertEquals(47561570, $timeslice1);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '819652', 3, 1426847190, $timeslice2));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '819652', 3, 1426847190, $timeslice2));
|
||||||
$this->assertEquals(1426847130, $timeslice2);
|
$this->assertEquals(47561571, $timeslice2);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '915954', 3, 1426847190, $timeslice3));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '915954', 3, 1426847190, $timeslice3));
|
||||||
$this->assertEquals(1426847160, $timeslice3);
|
$this->assertEquals(47561572, $timeslice3);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '543160', 3, 1426847190, $timeslice4));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '543160', 3, 1426847190, $timeslice4));
|
||||||
$this->assertEquals(1426847190, $timeslice4);
|
$this->assertEquals(47561573, $timeslice4);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '348401', 3, 1426847190, $timeslice5));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '348401', 3, 1426847190, $timeslice5));
|
||||||
$this->assertEquals(1426847220, $timeslice5);
|
$this->assertEquals(47561574, $timeslice5);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '648525', 3, 1426847190, $timeslice6));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '648525', 3, 1426847190, $timeslice6));
|
||||||
$this->assertEquals(1426847250, $timeslice6);
|
$this->assertEquals(47561575, $timeslice6);
|
||||||
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '170645', 3, 1426847190, $timeslice7));
|
$this->assertEquals(true, $tfa->verifyCode('VMR466AB62ZBOKHE', '170645', 3, 1426847190, $timeslice7));
|
||||||
$this->assertEquals(1426847280, $timeslice7);
|
$this->assertEquals(47561576, $timeslice7);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTotpUriIsCorrect() {
|
public function testTotpUriIsCorrect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user