Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
refactor: new digits length rule for 2FA setup (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Highjhacker authored Jun 22, 2021
1 parent ca9d6a5 commit a24ffa0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/views/auth/two-factor-challenge.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class="w-full"
:errors="$errors"
autocomplete="one-time-code"
input-mode="numeric"
pattern="[0-9]*"
pattern="[0-9]{6}"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
name="state.otp"
:label="trans('fortify::pages.user-settings.one_time_password')"
:errors="$errors"
pattern="[0-9]{6}"
/>
</div>
</div>
Expand Down Expand Up @@ -83,6 +84,7 @@
name="state.otp"
:label="trans('fortify::pages.user-settings.one_time_password')"
:errors="$errors"
pattern="[0-9]{6}""
/>
</div>
</div>
Expand All @@ -96,6 +98,7 @@
name="state.otp"
:label="trans('fortify::pages.user-settings.one_time_password')"
:errors="$errors"
pattern="[0-9]{6}"
/>
</div>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/Components/TwoFactorAuthenticationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class TwoFactorAuthenticationForm extends Component
use InteractsWithUser;
use HasModal;

protected $messages = [
'state.otp.digits' => 'One Time Password must be :digits digits.',
];

public bool $showingQrCode = false;

public array $state = [];
Expand All @@ -51,7 +55,7 @@ public function render(): View
public function enableTwoFactorAuthentication(): void
{
$this->validate([
'state.otp' => ['required', new OneTimePassword($this->state['two_factor_secret'])],
'state.otp' => ['required', 'digits:6', new OneTimePassword($this->state['two_factor_secret'])],
]);

app(EnableTwoFactorAuthentication::class)(Auth::user(), $this->state['two_factor_secret']);
Expand Down
3 changes: 3 additions & 0 deletions tests/Components/TwoFactorAuthenticationFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
->set('state.two_factor_secret', $two_factor_secret)
->assertSet('enabled', false)
->assertSee($two_factor_secret)
->set('state.otp', '8437339')
->call('enableTwoFactorAuthentication')
->assertHasErrors(['state.otp' => 'digits'])
->set('state.otp', '843733')
->call('enableTwoFactorAuthentication')
->assertSee('Two-Factor Authentication Recovery Codes')
Expand Down

0 comments on commit a24ffa0

Please sign in to comment.