Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Fixed code handling and persistence into a string.
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter committed Mar 17, 2021
1 parent 35da9e3 commit bc0cdf5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions config/laraguard.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@
| Safe Devices
|--------------------------------------------------------------------------
|
| Authenticating with Two Factor Codes can become very obnoxious if you do
| it every time, so for this reasons the Safe Devices can be enabled. It
| remembers the device with an long-lived cookie to bypass Two Factor.
| Authenticating with Two Factor Codes can become very obnoxious when the
| user does it every time. To "remember" a device where a 2FA code was
| validated to not ask again you can enable Safe Device to save it.
|
*/

Expand Down
3 changes: 2 additions & 1 deletion src/Eloquent/HandlesCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use Illuminate\Support\Carbon;
use ParagonIE\ConstantTime\Base32;

trait HandlesCodes
{
Expand Down Expand Up @@ -141,7 +142,7 @@ protected function timestampToBinary(int $timestamp)
*/
protected function getBinarySecret()
{
return $this->attributes['shared_secret'];
return Base32::decodeUpper($this->attributes['shared_secret']);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Eloquent/TwoFactorAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function test_generates_random_secret()
public function test_makes_code()
{
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
'shared_secret' => $secret = Base32::decodeUpper('KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3'),
'shared_secret' => $secret = 'KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3',
]);

Carbon::setTestNow(Carbon::create(2020, 1, 1, 20, 29, 59));
Expand Down Expand Up @@ -141,7 +141,7 @@ public function test_makes_code()
public function test_makes_code_for_timestamp()
{
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
'shared_secret' => $secret = Base32::decodeUpper('KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3'),
'shared_secret' => $secret = 'KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3',
]);

$this->assertEquals('566278', $tfa->makeCode(1581300000));
Expand All @@ -151,7 +151,7 @@ public function test_makes_code_for_timestamp()
public function test_validate_code()
{
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
'shared_secret' => $secret = Base32::decodeUpper('KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3'),
'shared_secret' => $secret = 'KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3',
'window' => 0,
]);

Expand All @@ -170,7 +170,7 @@ public function test_validate_code()
public function test_validate_code_with_window()
{
$tfa = TwoFactorAuthentication::factory()->withRecovery()->withSafeDevices()->make([
'shared_secret' => $secret = Base32::decodeUpper('KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3'),
'shared_secret' => $secret = 'KS72XBTN5PEBGX2IWBMVW44LXHPAQ7L3',
'window' => 1,
]);

Expand Down

0 comments on commit bc0cdf5

Please sign in to comment.