|
Lines 729-749
Exceptions are thrown if the password is not good enough.
Link Here
|
| 729 |
sub set_password { |
729 |
sub set_password { |
| 730 |
my ( $self, $password ) = @_; |
730 |
my ( $self, $password ) = @_; |
| 731 |
|
731 |
|
| 732 |
my $min_length = C4::Context->preference('minPasswordLength'); |
732 |
my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); |
| 733 |
$min_length = 3 if not $min_length or $min_length < 3; |
|
|
| 734 |
|
733 |
|
| 735 |
my $password_length = length($password); |
734 |
if ( !$is_valid ) { |
| 736 |
Koha::Exceptions::Password::TooShort->throw( |
735 |
if ( $error eq 'too_short' ) { |
| 737 |
{ length => $password_length, min_length => $min_length } ) |
736 |
my $min_length = C4::Context->preference('minPasswordLength'); |
| 738 |
if $password_length < $min_length; |
737 |
$min_length = 3 if not $min_length or $min_length < 3; |
| 739 |
|
738 |
|
| 740 |
Koha::Exceptions::Password::TrailingWhitespaces->throw( |
739 |
my $password_length = length($password); |
| 741 |
"Password contains trailing spaces, which is forbidden.") |
740 |
Koha::Exceptions::Password::TooShort->throw( |
| 742 |
if $password =~ m[^\s|\s$]; |
741 |
{ length => $password_length, min_length => $min_length } ); |
| 743 |
|
742 |
} |
| 744 |
if ( C4::Context->preference('RequireStrongPassword') ) { |
743 |
elsif ( $error eq 'has_whitespaces' ) { |
| 745 |
Koha::Exceptions::Password::TooWeak->throw() |
744 |
Koha::Exceptions::Password::TrailingWhitespaces->throw( |
| 746 |
if $password !~ m|(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{$min_length,}|; |
745 |
"Password contains trailing spaces, which is forbidden."); |
|
|
746 |
} |
| 747 |
elsif ( $error eq 'too_weak' ) { |
| 748 |
Koha::Exceptions::Password::TooWeak->throw(); |
| 749 |
} |
| 747 |
} |
750 |
} |
| 748 |
|
751 |
|
| 749 |
my $digest = Koha::AuthUtils::hash_password($password); |
752 |
my $digest = Koha::AuthUtils::hash_password($password); |