Lines 32-37
use Koha::AuthUtils;
Link Here
|
32 |
use Koha::Checkouts; |
32 |
use Koha::Checkouts; |
33 |
use Koha::Database; |
33 |
use Koha::Database; |
34 |
use Koha::DateUtils; |
34 |
use Koha::DateUtils; |
|
|
35 |
use Koha::Exceptions::Password; |
35 |
use Koha::Holds; |
36 |
use Koha::Holds; |
36 |
use Koha::Old::Checkouts; |
37 |
use Koha::Old::Checkouts; |
37 |
use Koha::Patron::Categories; |
38 |
use Koha::Patron::Categories; |
Lines 652-657
sub update_password {
Link Here
|
652 |
return $digest; |
653 |
return $digest; |
653 |
} |
654 |
} |
654 |
|
655 |
|
|
|
656 |
=head3 set_password |
657 |
|
658 |
$patron->set_password( $plain_text_password ); |
659 |
|
660 |
Set the patron's password. |
661 |
|
662 |
=head4 Exceptions |
663 |
|
664 |
The passed string is validated against the current password enforcement policy. |
665 |
Exceptions are thrown if the password is not good enough. |
666 |
|
667 |
=over 4 |
668 |
|
669 |
=item Koha::Exceptions::Password::TooShort |
670 |
|
671 |
=item Koha::Exceptions::Password::TrailingWhitespaces |
672 |
|
673 |
=item Koha::Exceptions::Password::TooWeak |
674 |
|
675 |
=back |
676 |
|
677 |
=cut |
678 |
|
679 |
sub set_password { |
680 |
my ( $self, $password ) = @_; |
681 |
|
682 |
my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); |
683 |
|
684 |
if ( !$is_valid ) { |
685 |
if ( $error eq 'too_short' ) { |
686 |
my $min_length = C4::Context->preference('minPasswordLength'); |
687 |
$min_length = 3 if not $min_length or $min_length < 3; |
688 |
|
689 |
my $password_length = length($password); |
690 |
Koha::Exceptions::Password::TooShort->throw( |
691 |
{ length => $password_length, min_length => $min_length } ); |
692 |
} |
693 |
elsif ( $error eq 'has_whitespaces' ) { |
694 |
Koha::Exceptions::Password::TrailingWhitespaces->throw( |
695 |
"Password contains trailing spaces, which is forbidden."); |
696 |
} |
697 |
elsif ( $error eq 'too_weak' ) { |
698 |
Koha::Exceptions::Password::TooWeak->throw(); |
699 |
} |
700 |
} |
701 |
|
702 |
my $digest = Koha::AuthUtils::hash_password($password); |
703 |
$self->update( |
704 |
{ password => $digest, |
705 |
login_attempts => 0, |
706 |
} |
707 |
); |
708 |
|
709 |
logaction( "MEMBERS", "CHANGE PASS", $self->borrowernumber, "" ) |
710 |
if C4::Context->preference("BorrowersLog"); |
711 |
|
712 |
return $self; |
713 |
} |
714 |
|
715 |
|
655 |
=head3 renew_account |
716 |
=head3 renew_account |
656 |
|
717 |
|
657 |
my $new_expiry_date = $patron->renew_account |
718 |
my $new_expiry_date = $patron->renew_account |
658 |
- |
|
|