Give the machine console its own session with PIN sign-in, make counters cumulative
The console under console/ has its own session cookie and console guard (UseConsoleSession), so signing out or changing user there leaves the normal interface alone. Links open it in a new window through a one-time handoff key; a signed-out console asks for a PIN code or password on its own login page. Users set their 4-6 digit PIN on the profile's PIN page, and the console's change user dialog takes it on a keypad; five wrong PINs lock PIN sign-in for 15 minutes. Machine counters are cumulative: users record how much a job used and it is added to the latest reading. A maintenance record restarts the whole counter interval from the reading at the record. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -1,25 +1,12 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Users\Application\UseCases\CheckLoginAllowed;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use App\Modules\Users\Presentation\Livewire\Concerns\SignsInWithPassword;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public const int MAX_ATTEMPTS_PER_MINUTE = 5;
|
||||
|
||||
/**
|
||||
* Failed attempts from one address across all accounts, so one common
|
||||
* password cannot be tried on every account (password spraying).
|
||||
*/
|
||||
public const int MAX_ATTEMPTS_PER_IP_PER_MINUTE = 20;
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $password = '';
|
||||
use SignsInWithPassword;
|
||||
|
||||
public bool $remember = false;
|
||||
|
||||
@@ -37,47 +24,7 @@ new class extends Component
|
||||
|
||||
public function login(CheckLoginAllowed $checkLoginAllowed): void
|
||||
{
|
||||
$this->email = trim($this->email);
|
||||
|
||||
$this->validate(
|
||||
['email' => ['required', 'string', 'email'], 'password' => ['required', 'string']],
|
||||
[
|
||||
'email.required' => __('auth.email_required'),
|
||||
'email.email' => __('auth.email_invalid'),
|
||||
'password.required' => __('auth.password_required'),
|
||||
],
|
||||
);
|
||||
|
||||
$email = Str::lower(trim($this->email));
|
||||
$throttleKey = Str::transliterate($email.'|'.request()->ip());
|
||||
$ipThrottleKey = 'login-ip|'.request()->ip();
|
||||
|
||||
foreach ([$throttleKey => self::MAX_ATTEMPTS_PER_MINUTE, $ipThrottleKey => self::MAX_ATTEMPTS_PER_IP_PER_MINUTE] as $key => $maxAttempts) {
|
||||
if (RateLimiter::tooManyAttempts($key, $maxAttempts)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => __('auth.throttle', ['seconds' => RateLimiter::availableIn($key)]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$signedIn = Auth::attemptWhen(
|
||||
['email' => $email, 'password' => $this->password],
|
||||
fn ($user): bool => $checkLoginAllowed->execute($user->getAuthIdentifier()),
|
||||
$this->remember,
|
||||
);
|
||||
|
||||
if (! $signedIn) {
|
||||
RateLimiter::hit($throttleKey);
|
||||
RateLimiter::hit($ipThrottleKey);
|
||||
$this->reset('password');
|
||||
|
||||
// One message for a wrong password and a disabled account, so the
|
||||
// form never confirms that a disabled account's password is right.
|
||||
throw ValidationException::withMessages(['email' => __('auth.failed')]);
|
||||
}
|
||||
|
||||
RateLimiter::clear($throttleKey);
|
||||
session()->regenerate();
|
||||
$this->signInWithPassword($checkLoginAllowed, $this->remember);
|
||||
|
||||
$this->redirectIntended(route('home'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user