How would I log failed login attempts with laravel 5.2 I have the auth scaffolding installed.
I have added the following to my EventsServiceProvider.php
protected $listen = [
'Illuminate\Auth\Events\Attempting' => [
'App\Listeners\LogAuthenticationAttempt',
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogSuccessfulLogin',
],
'Illuminate\Auth\Events\Logout' => [
'App\Listeners\LogSuccessfulLogout',
],
'Illuminate\Auth\Events\Lockout' => [
'App\Listeners\LogLockout',
],
];
And in my app/Listeners/LogAuthenticationAttempt.php
I have
$log = new Access_Log();
$log->ip_address = Request::getClientIp();
$log->is_success = 0;
$log->save();
But this just logs that an login attempt has been made> I can log a successful login attempt using the LogSuccessfulLogin Listener but I cant see how to log a failed login attempt.
It has occurred to me that I could just update the is_success value on the log entry in the LogSuccessfulLogin Listener but what can I use to persist between LogAuthenticationAttempt and LogSuccessfulLogin to identify this as the same login attempt?
Turns out there was a failed event it just wasn't in the docs I was following. See Pervara's comment.
I added this to the EventsServiceProvider.php:
And created app/Listeners/LogFailedAuthenticationAttempt.php with the following code:
Works perfectly.