@@ -164,12 +164,17 @@ public function generateRecoveryCodes(): array
164164 return Collection::times ($ this ->getRecoveryCodeCount (), fn (): string => Str::random (10 ) . '- ' . Str::random (10 ))->all ();
165165 }
166166
167- public function verifyCode (string $ code , ?string $ secret = null ): bool
167+ public function verifyCode (string $ code , ?string $ secret = null , bool $ shouldPreventCodeReuse = false ): bool
168168 {
169169 /** @var HasAppAuthentication $user */
170170 $ user = Filament::auth ()->user ();
171171
172172 $ secret = $ secret ?? $ this ->getSecret ($ user );
173+
174+ if (! $ shouldPreventCodeReuse ) {
175+ return $ this ->google2FA ->verifyKey ($ secret , $ code , $ this ->getCodeWindow ());
176+ }
177+
173178 $ cacheKey = 'filament.app_authentication_codes. ' . md5 ($ secret . $ code );
174179
175180 $ timestamp = $ this ->google2FA ->verifyKeyNewer ($ secret , $ code , cache ()->get ($ cacheKey ), $ this ->getCodeWindow ());
@@ -327,7 +332,7 @@ public function getChallengeFormComponents(Authenticatable $user): array
327332 ->required (fn (Get $ get ): bool => (! $ isRecoverable ) || blank ($ get ('recoveryCode ' )))
328333 ->rule (function () use ($ user ): Closure {
329334 return function (string $ attribute , $ value , Closure $ fail ) use ($ user ): void {
330- if ($ this ->verifyCode ($ value , $ this ->getSecret ($ user ))) {
335+ if ($ this ->verifyCode ($ value , $ this ->getSecret ($ user ), shouldPreventCodeReuse: true )) {
331336 return ;
332337 }
333338
0 commit comments