*/ public function rules(): array { return [ 'email' => ['required', 'string', 'email'], 'password' => ['required', 'string'], ]; } public function messages() { return [ 'email.required' => get_phrase('Email is required'), 'password.required' => get_phrase('Password is required'), 'email.email' => get_phrase('Please enter a valid email address'), ]; } public function withValidator($validator) { $validator->after(function ($validator) { if ($validator->failed()) { Session::flash('error', get_phrase('Please fill in all the required fields correctly.')); } }); } /** * Attempt to authenticate the request's credentials. * * @throws \Illuminate\Validation\ValidationException */ public function authenticate() { $this->ensureIsNotRateLimited(); // Custom validation before attempting login if (empty($this->email) || empty($this->password)) { Session::flash('error', get_phrase('Email or password is empty. Please fill in all the required fields.')); throw ValidationException::withMessages([ 'email' => '', // Empty message to avoid default validation messages ]); } if (!Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { RateLimiter::hit($this->throttleKey()); Session::flash('error', get_phrase('Login failed. Please check your email and password.')); throw ValidationException::withMessages([ 'email' => '', // Empty message to avoid default validation messages ]); } RateLimiter::clear($this->throttleKey()); } /** * Ensure the login request is not rate limited. * * @throws \Illuminate\Validation\ValidationException */ public function ensureIsNotRateLimited(): void { if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { return; } event(new Lockout($this)); $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ 'email' => trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), ]); } /** * Get the rate limiting throttle key for the request. */ public function throttleKey(): string { return Str::transliterate(Str::lower($this->input('email')).'|'.$this->ip()); } }