get('tmpUserOTP')) { return false; } return true; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'otp' => [ 'string', 'required', function ($attribute, $value, $fail) { $user = session()->get('tmpUserOTP'); $lastCode = (new Totp())->GenerateToken( Base32::decode($user->totp_secret), Carbon::now()->subSeconds(30)->timestamp ); $code = (new Totp())->GenerateToken(Base32::decode($user->totp_secret)); if (!($value === $code || $value === $lastCode)) { $fail("Code de vérification $attribute invalide."); } } ] ]; } }