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

Commit

Permalink
Merge pull request #35 from DarkGhostHunter/master
Browse files Browse the repository at this point in the history
Fixes validation for recovery codes.
  • Loading branch information
DarkGhostHunter committed Jun 8, 2020
2 parents 1682dac + 2571b9f commit 3072728
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Rules/TotpCodeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Translator $translator, Authenticatable $user = null
*/
public function validate($attribute, $value)
{
if (is_numeric($value) && $this->user instanceof TwoFactorAuthenticatable) {
if (is_string($value) && $this->user instanceof TwoFactorAuthenticatable) {
return $this->user->validateTwoFactorCode($value);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Rules/TotpRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ public function test_validator_succeeds_if_code_valid()
$this->assertFalse($fails);
}

public function test_validator_succeeds_if_code_is_recovery()
{
$this->app['auth']->guard()->setUser($this->user);

$fails = validator([
'totp_code' => $this->user->generateRecoveryCodes()->first()['code']
], [
'totp_code' => 'totp_code'
])->fails();

$this->assertFalse($fails);
}

public function test_validator_rule_uses_translation()
{
$validator = validator([
Expand Down

0 comments on commit 3072728

Please sign in to comment.