@@ -, +, @@ database - Setting a password for a new user - Changing a password in the staff client - Changing a password in the OPAC --- Koha/Exceptions/Password.pm | 6 ++- Koha/Patron.pm | 46 +++++++++++++++++++++- .../prog/en/modules/members/member-password.tt | 3 ++ members/member-password.pl | 3 ++ 4 files changed, 56 insertions(+), 2 deletions(-) --- a/Koha/Exceptions/Password.pm +++ a/Koha/Exceptions/Password.pm @@ -38,7 +38,11 @@ use Exception::Class ( 'Koha::Exceptions::Password::WhitespaceCharacters' => { isa => 'Koha::Exceptions::Password', description => 'Password contains leading/trailing whitespace character(s)' - } + }, + 'Koha::Exceptions::Password::Plugin' => { + isa => 'Koha::Exceptions::Password', + description => 'The password was rejected by a plugin' + }, ); sub full_message { --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -43,6 +43,8 @@ use Koha::Patron::HouseboundRole; use Koha::Patron::Images; use Koha::Patron::Relationships; use Koha::Patrons; +use Koha::Plugins; +use Koha::Plugins::Handler; use Koha::Subscription::Routinglists; use Koha::Token; use Koha::Virtualshelves; @@ -223,7 +225,6 @@ sub store { : undef; $self->privacy($default_privacy); - # Make a copy of the plain text password for later use $self->plain_text_password( $self->password ); @@ -240,6 +241,27 @@ sub store { logaction( "MEMBERS", "CREATE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); + + if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { + # Call any check_password plugins + my @plugins = Koha::Plugins->new()->GetPlugins({ + method => 'check_password', + }); + foreach my $plugin ( @plugins ) { + my $ret = Koha::Plugins::Handler->run({ + class => ref $plugin, + method => 'check_password', + params => { + password => $self->plain_text_password, + borrowernumber => $self->borrowernumber, + }, + }); + if ( $ret->{'error'} == 1 ) { + Koha::Exceptions::Password::Plugin->throw(); + } + } + } + } else { #ModMember @@ -682,6 +704,8 @@ Exceptions are thrown if the password is not good enough. =item Koha::Exceptions::Password::TooWeak +=item Koha::Exceptions::Password::Plugin (if a "check password" plugin is enabled) + =back =cut @@ -712,6 +736,26 @@ sub set_password { } } + if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) { + # Call any check_password plugins + my @plugins = Koha::Plugins->new()->GetPlugins({ + method => 'check_password', + }); + foreach my $plugin ( @plugins ) { + my $ret = Koha::Plugins::Handler->run({ + class => ref $plugin, + method => 'check_password', + params => { + password => $password, + borrowernumber => $self->borrowernumber, + }, + }); + if ( $ret->{'error'} == 1 ) { + Koha::Exceptions::Password::Plugin->throw(); + } + } + } + my $digest = Koha::AuthUtils::hash_password($password); $self->update( { password => $digest, --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member-password.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member-password.tt @@ -45,6 +45,9 @@ [% IF ( ERROR_password_has_whitespaces ) %]
  • Password must not contain leading or trailing whitespaces.
  • [% END %] + [% IF ( ERROR_from_plugin ) %] +
  • The password was rejected by a plugin.
  • + [% END %] [% IF ( NOPERMISSION ) %]
  • You do not have permission to edit this patron's login information.
  • [% END %] --- a/members/member-password.pl +++ a/members/member-password.pl @@ -91,6 +91,9 @@ if ( $newpassword and not @errors) { elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) { push @errors, 'ERROR_password_too_weak'; } + elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) { + push @errors, 'ERROR_from_plugin'; + } else { push( @errors, 'BADUSERID' ); } --