View | Details | Raw Unified | Return to bug 21178
Collapse All | Expand All

(-)a/Koha/Patron.pm (-13 / +16 lines)
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);
(-)a/t/db_dependent/Koha/Patrons.t (-2 / +1 lines)
Lines 1529-1535 subtest '->set_password' => sub { Link Here
1529
        'minPasswordLength is 5, fail test';
1529
        'minPasswordLength is 5, fail test';
1530
1530
1531
    # Trailing spaces tests
1531
    # Trailing spaces tests
1532
    throws_ok { $patron->set_password('abcd   '); }
1532
    throws_ok { $patron->set_password('abcD12d   '); }
1533
        'Koha::Exceptions::Password::TrailingWhitespaces',
1533
        'Koha::Exceptions::Password::TrailingWhitespaces',
1534
        'Password contains trailing spaces, exception is thrown';
1534
        'Password contains trailing spaces, exception is thrown';
1535
1535
1536
- 

Return to bug 21178