-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a setting for the allowed time discrepancy
- Loading branch information
Christopher Mühl
committed
Jan 5, 2018
1 parent
3dbc7e1
commit 50d341b
Showing
9 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_CONFIG']['tfaTtopDiscrepancy'] = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_DCA']['tl_settings']['fields']['tfaTtopDiscrepancy'] = [ | ||
'label' => &$GLOBALS['TL_LANG']['tl_settings']['tfaTtopDiscrepancy'], | ||
'inputType' => 'text', | ||
'eval' => ['minval' => '0', 'rgxp' => 'natural', 'tl_class' => 'w50'], | ||
'default' => '1', | ||
]; | ||
|
||
// Add the TTOP discrepancy setting | ||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] = str_replace( | ||
'allowedTags', | ||
'allowedTags,tfaTtopDiscrepancy', | ||
$GLOBALS['TL_DCA']['tl_settings']['palettes']['default'] | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_settings']['tfaTtopDiscrepancy'][0] = 'Erlaubte 2FA-Diskrepanz'; | ||
$GLOBALS['TL_LANG']['tl_settings']['tfaTtopDiscrepancy'][1] = 'Gibt an wie viele Perioden der eingegebene 2FA-Code vom Server-Code abweichen kann (z.B. 1 erlaubt eine Abweichung von ±30 Sekunden, 2 erlaubt ±60 Sekunden, …)'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
|
||
$GLOBALS['TL_LANG']['tl_settings']['tfaTtopDiscrepancy'][0] = 'Allowed 2FA discrepancy'; | ||
$GLOBALS['TL_LANG']['tl_settings']['tfaTtopDiscrepancy'][1] = 'Specifies how many periods the entered 2FA code can deviate from the server-code (e.g. 1 allows for a deviation of ±30 seconds, 2 allows for ±60 seconds, …)'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace DieSchittigs\TwoFactorAuth; | ||
|
||
use RobThree\Auth\TwoFactorAuth; | ||
|
||
|
||
class TwoFactorFactory | ||
{ | ||
/** | ||
* Generates a TwoFactorAuth object with the website title as its label | ||
* | ||
* @return TwoFactorAuth | ||
*/ | ||
public static function generate() | ||
{ | ||
$title = $GLOBALS['TL_CONFIG']['websiteTitle']; | ||
return new TwoFactorAuth($title); | ||
} | ||
|
||
/** | ||
* Verifies a code with the configured discrepancy | ||
* | ||
* @param string $secret The secret to verify the code with | ||
* @param string $code The code to verify | ||
* @return boolean | ||
*/ | ||
public static function verifyCode($secret, $code) | ||
{ | ||
$discrepancy = (int) $GLOBALS['TL_CONFIG']['tfaTtopDiscrepancy']; | ||
|
||
if ($discrepancy < 0) { | ||
// Make sure the discrepancy is positive, otherwise we're stuck in an infinite loop. | ||
$discrepancy = -$discrepancy; | ||
} | ||
|
||
$auth = self::generate(); | ||
return $auth->verifyCode($secret, $code, $discrepancy); | ||
} | ||
} |