]> BookStack Code Mirror - bookstack/blob - app/Access/Mfa/TotpValidationRule.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Access / Mfa / TotpValidationRule.php
1 <?php
2
3 namespace BookStack\Access\Mfa;
4
5 use Closure;
6 use Illuminate\Contracts\Validation\ValidationRule;
7
8 class TotpValidationRule implements ValidationRule
9 {
10     /**
11      * Create a new rule instance.
12      * Takes the TOTP secret that must be system provided, not user provided.
13      */
14     public function __construct(
15         protected string $secret,
16         protected TotpService $totpService,
17     ) {
18     }
19
20     public function validate(string $attribute, mixed $value, Closure $fail): void
21     {
22         $passes = $this->totpService->verifyCode($value, $this->secret);
23         if (!$passes) {
24             $fail(trans('validation.totp'));
25         }
26     }
27 }