*/ #[Computed] public function pinUsers(): array { return app(UserAccountQueries::class)->pinLoginOptions(); } /** * @return bool Whether the user is now signed in. */ protected function signInWithPin(LoginPins $pins): bool { $this->resetErrorBag(); $user = collect($this->pinUsers)->firstWhere('id', (int) $this->userId); if ($user === null) { $this->addError('userId', __('users.pin_switch.errors.user')); return false; } $userKey = 'pin-login|user|'.$user->id; $ipKey = 'pin-login|ip|'.request()->ip(); foreach ([[$userKey, 5], [$ipKey, 20]] as [$key, $max]) { if (RateLimiter::tooManyAttempts($key, $max)) { $this->addError('pin', __('users.pin_switch.errors.locked', ['minutes' => (int) ceil(RateLimiter::availableIn($key) / 60)])); $this->pin = ''; return false; } } RateLimiter::hit($ipKey, 60); if (! $pins->verify($user->id, $this->pin)) { RateLimiter::hit($userKey, 900); $this->addError('pin', __('users.pin_switch.errors.pin')); $this->pin = ''; return false; } RateLimiter::clear($userKey); if (Auth::check()) { Auth::logout(); session()->invalidate(); session()->regenerateToken(); } Auth::loginUsingId($user->id); session()->regenerate(); return true; } }