|
Lines 670-682
sub update_password {
Link Here
|
| 670 |
|
670 |
|
| 671 |
=head3 set_password |
671 |
=head3 set_password |
| 672 |
|
672 |
|
| 673 |
$patron->set_password( $plain_text_password ); |
673 |
$patron->set_password({ password => $plain_text_password [, skip_validation => 1 ] }); |
| 674 |
|
674 |
|
| 675 |
Set the patron's password. |
675 |
Set the patron's password. |
| 676 |
|
676 |
|
| 677 |
=head4 Exceptions |
677 |
=head4 Exceptions |
| 678 |
|
678 |
|
| 679 |
The passed string is validated against the current password enforcement policy. |
679 |
The passed string is validated against the current password enforcement policy. |
|
|
680 |
Validation can be skipped by passing the I<skip_validation> parameter. |
| 681 |
|
| 680 |
Exceptions are thrown if the password is not good enough. |
682 |
Exceptions are thrown if the password is not good enough. |
| 681 |
|
683 |
|
| 682 |
=over 4 |
684 |
=over 4 |
|
Lines 692-715
Exceptions are thrown if the password is not good enough.
Link Here
|
| 692 |
=cut |
694 |
=cut |
| 693 |
|
695 |
|
| 694 |
sub set_password { |
696 |
sub set_password { |
| 695 |
my ( $self, $password ) = @_; |
697 |
my ( $self, $args ) = @_; |
| 696 |
|
698 |
|
| 697 |
my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); |
699 |
my $password = $args->{password}; |
| 698 |
|
700 |
|
| 699 |
if ( !$is_valid ) { |
701 |
unless ( $args->{skip_validation} ) { |
| 700 |
if ( $error eq 'too_short' ) { |
702 |
my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); |
| 701 |
my $min_length = C4::Context->preference('minPasswordLength'); |
|
|
| 702 |
$min_length = 3 if not $min_length or $min_length < 3; |
| 703 |
|
703 |
|
| 704 |
my $password_length = length($password); |
704 |
if ( !$is_valid ) { |
| 705 |
Koha::Exceptions::Password::TooShort->throw( |
705 |
if ( $error eq 'too_short' ) { |
| 706 |
{ length => $password_length, min_length => $min_length } ); |
706 |
my $min_length = C4::Context->preference('minPasswordLength'); |
| 707 |
} |
707 |
$min_length = 3 if not $min_length or $min_length < 3; |
| 708 |
elsif ( $error eq 'has_whitespaces' ) { |
708 |
|
| 709 |
Koha::Exceptions::Password::WhitespaceCharacters->throw(); |
709 |
my $password_length = length($password); |
| 710 |
} |
710 |
Koha::Exceptions::Password::TooShort->throw( |
| 711 |
elsif ( $error eq 'too_weak' ) { |
711 |
{ length => $password_length, min_length => $min_length } ); |
| 712 |
Koha::Exceptions::Password::TooWeak->throw(); |
712 |
} |
|
|
713 |
elsif ( $error eq 'has_whitespaces' ) { |
| 714 |
Koha::Exceptions::Password::WhitespaceCharacters->throw(); |
| 715 |
} |
| 716 |
elsif ( $error eq 'too_weak' ) { |
| 717 |
Koha::Exceptions::Password::TooWeak->throw(); |
| 718 |
} |
| 713 |
} |
719 |
} |
| 714 |
} |
720 |
} |
| 715 |
|
721 |
|
| 716 |
- |
|
|