|
Lines 33-38
use Koha::AuthUtils;
Link Here
|
| 33 |
use Koha::Checkouts; |
33 |
use Koha::Checkouts; |
| 34 |
use Koha::Database; |
34 |
use Koha::Database; |
| 35 |
use Koha::DateUtils; |
35 |
use Koha::DateUtils; |
|
|
36 |
use Koha::Exceptions::Password; |
| 36 |
use Koha::Holds; |
37 |
use Koha::Holds; |
| 37 |
use Koha::Old::Checkouts; |
38 |
use Koha::Old::Checkouts; |
| 38 |
use Koha::Patron::Categories; |
39 |
use Koha::Patron::Categories; |
|
Lines 702-707
sub update_password {
Link Here
|
| 702 |
return $digest; |
703 |
return $digest; |
| 703 |
} |
704 |
} |
| 704 |
|
705 |
|
|
|
706 |
=head3 set_password |
| 707 |
|
| 708 |
$patron->set_password( $plain_text_password ); |
| 709 |
|
| 710 |
Set the patron's password. |
| 711 |
|
| 712 |
=head4 Exceptions |
| 713 |
|
| 714 |
The passed string is validated against the current password enforcement policy. |
| 715 |
Exceptions are thrown if the password is not good enough. |
| 716 |
|
| 717 |
=over 4 |
| 718 |
|
| 719 |
=item Koha::Exceptions::Password::TooShort |
| 720 |
|
| 721 |
=item Koha::Exceptions::Password::TrailingWhitespaces |
| 722 |
|
| 723 |
=item Koha::Exceptions::Password::TooWeak |
| 724 |
|
| 725 |
=back |
| 726 |
|
| 727 |
=cut |
| 728 |
|
| 729 |
sub set_password { |
| 730 |
my ( $self, $password ) = @_; |
| 731 |
|
| 732 |
my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); |
| 733 |
|
| 734 |
if ( !$is_valid ) { |
| 735 |
if ( $error eq 'too_short' ) { |
| 736 |
my $min_length = C4::Context->preference('minPasswordLength'); |
| 737 |
$min_length = 3 if not $min_length or $min_length < 3; |
| 738 |
|
| 739 |
my $password_length = length($password); |
| 740 |
Koha::Exceptions::Password::TooShort->throw( |
| 741 |
{ length => $password_length, min_length => $min_length } ); |
| 742 |
} |
| 743 |
elsif ( $error eq 'has_whitespaces' ) { |
| 744 |
Koha::Exceptions::Password::TrailingWhitespaces->throw( |
| 745 |
"Password contains trailing spaces, which is forbidden."); |
| 746 |
} |
| 747 |
elsif ( $error eq 'too_weak' ) { |
| 748 |
Koha::Exceptions::Password::TooWeak->throw(); |
| 749 |
} |
| 750 |
} |
| 751 |
|
| 752 |
my $digest = Koha::AuthUtils::hash_password($password); |
| 753 |
$self->update( |
| 754 |
{ password => $digest, |
| 755 |
login_attempts => 0, |
| 756 |
} |
| 757 |
); |
| 758 |
|
| 759 |
logaction( "MEMBERS", "CHANGE PASS", $self->borrowernumber, "" ) |
| 760 |
if C4::Context->preference("BorrowersLog"); |
| 761 |
|
| 762 |
return $self; |
| 763 |
} |
| 764 |
|
| 765 |
|
| 705 |
=head3 renew_account |
766 |
=head3 renew_account |
| 706 |
|
767 |
|
| 707 |
my $new_expiry_date = $patron->renew_account |
768 |
my $new_expiry_date = $patron->renew_account |
| 708 |
- |
|
|