Support the ongoing development of Laravel.io →
Authentication Validation
Last updated 1 year ago.
0

The message your are getting is coming from Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers trait

you will need to override the postLogin method in your App\Http\Controllers\Auth\AuthController class. I don't see any other way of doing it :(

0

Thanks man, I'll try do this for now and will get the workaround later

0

It's quite simple. You need to copy the postLogin method from Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers and paste to App\Http\Controllers\Auth\AuthController class and change the error message as you like.

I think they need to add these messages on to a language file so anyone can change them :)

0

awesome, thanks!

0

one more thing though:

It's possible to only override the getFailedLoginMessage() if you don't want to double the whole logic there (which I find preferrable in this situation). Seems that the location of the trait in Laravel 5.1 has changed since the last post in this thread, this is why I post this additional information.

I just came across the same Problem in Laravel 5.1 (if somebody shall stumble over this very same thing). However I found the function getFailedLoginMessage():

protected function getFailedLoginMessage()
{
    return 'These credentials do not match our records.';
}

in the trait file:

vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php

used by the Auth Controller:

app\Http\Controllers\Auth\AuthController.php

I found out it is enough to overwrite the getFailedLoginMessage() like so:

protected function getFailedLoginMessage()
{
	return 'YourCustomMessage';
}    

So if you defined something like this in your lang/en/validation.php:

 'wrong_credentials'		=> 'Wrong Credentials dude!',

you could use it like this to have it translated:

protected function getFailedLoginMessage()
{
	return trans('validation.wrong_credentials');
}    

worked like a charm for me :)

Last updated 8 years ago.
0

marco-solare said:

worked like a charm for me :)

Worked perfectly. Thanks ! :)

0

marco-solare said:

one more thing though:

It's possible to only override the getFailedLoginMessage() if you don't want to double the whole logic there (which I find preferrable in this situation). Seems that the location of the trait in Laravel 5.1 has changed since the last post in this thread, this is why I post this additional information.

worked like a charm for me :)

Thanks, worked as expected. Actually the best way to handle this i found on the forums.

0

Just to continue this thread moving, the method was changed again.

The new method to override is:

protected function sendFailedLoginResponse(Request $request)
{
   throw ValidationException::withMessages([
      $this->username() => [trans('auth.failed')],
   ]);
}

So, pasting that in the LoginController will let you change the default message. Please note it has to be an array, so, the sample would be:

protected function sendFailedLoginResponse(Request $request)
{
       throw ValidationException::withMessages([
          $this->username() => ['YourCustomMessageGoesHere'],
       ]);
}

Naturally, having a lang file as suggested above is a far cleaner/leaner solution, just wanted to add my 2 cents.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dieg0 dieg0 Joined 30 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.