From 3009f7b122311047969185d33d3dc594a4298980 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 25 Oct 2019 09:55:32 +0000 Subject: [PATCH] Bug 21190: Add authentication logging to checkpw Content-Type: text/plain; charset=utf-8 Add optional logging for successful and failing login attempts in checkpw. Test plan: Enable the preferences Perform a good login and a bad attempt Check action_logs Signed-off-by: Marcel de Rooy Signed-off-by: Jon Knight Signed-off-by: Michal Denar --- C4/Auth.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/C4/Auth.pm b/C4/Auth.pm index dc83ac4ea0..a4e5bd85f6 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -45,6 +45,7 @@ use List::MoreUtils qw/ any /; use Encode qw( encode is_utf8); use C4::Auth_with_shibboleth; use Net::CIDR; +use C4::Log qw/logaction/; # use utf8; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug $ldap $cas $caslogout); @@ -1861,6 +1862,14 @@ sub checkpw { $patron->update({ login_attempts => $patron->login_attempts + 1 }); } } + + # Optionally log success or failure + if( $patron && $passwd_ok && C4::Context->preference('AuthSuccessLog') ) { + logaction( 'AUTH', 'SUCCESS', $patron->id, "Valid password for $userid", $type ); + } elsif( !$passwd_ok && C4::Context->preference('AuthFailureLog') ) { + logaction( 'AUTH', 'FAILURE', 0, "Wrong password for $userid", $type ); + } + return @return; } -- 2.11.0