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

(-)a/Koha/AuthUtils.pm (-3 / +10 lines)
Lines 151-163 sub is_password_valid { Link Here
151
    my $minPasswordLength = C4::Context->preference('minPasswordLength');
151
    my $minPasswordLength = C4::Context->preference('minPasswordLength');
152
    $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3;
152
    $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3;
153
    if ( length($password) < $minPasswordLength ) {
153
    if ( length($password) < $minPasswordLength ) {
154
        return ( 0, 'too_short' );
154
        my $min_length = C4::Context->preference('minPasswordLength');
155
        $min_length = 3 if not $min_length or $min_length < 3;
156
157
        my $password_length = length($password);
158
        Koha::Exceptions::Password::TooShort->throw(
159
            length => $password_length, min_length => $min_length
160
        );
155
    }
161
    }
156
    elsif ( C4::Context->preference('RequireStrongPassword') ) {
162
    elsif ( C4::Context->preference('RequireStrongPassword') ) {
157
        return ( 0, 'too_weak' )
163
        Koha::Exceptions::Password::TooWeak->throw()
158
          if $password !~ m|(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{$minPasswordLength,}|;
164
          if $password !~ m|(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{$minPasswordLength,}|;
159
    }
165
    }
160
    return ( 0, 'has_whitespaces' ) if $password =~ m[^\s|\s$];
166
    Koha::Exceptions::Password::WhitespaceCharacters->throw()
167
        if $password =~ m[^\s|\s$];
161
    return ( 1, undef );
168
    return ( 1, undef );
162
}
169
}
163
170
(-)a/Koha/Patron.pm (-18 lines)
Lines 693-715 sub set_password { Link Here
693
693
694
    unless ( $args->{skip_validation} ) {
694
    unless ( $args->{skip_validation} ) {
695
        my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password );
695
        my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password );
696
697
        if ( !$is_valid ) {
698
            if ( $error eq 'too_short' ) {
699
                my $min_length = C4::Context->preference('minPasswordLength');
700
                $min_length = 3 if not $min_length or $min_length < 3;
701
702
                my $password_length = length($password);
703
                Koha::Exceptions::Password::TooShort->throw(
704
                    length => $password_length, min_length => $min_length );
705
            }
706
            elsif ( $error eq 'has_whitespaces' ) {
707
                Koha::Exceptions::Password::WhitespaceCharacters->throw();
708
            }
709
            elsif ( $error eq 'too_weak' ) {
710
                Koha::Exceptions::Password::TooWeak->throw();
711
            }
712
        }
713
    }
696
    }
714
697
715
    my $digest = Koha::AuthUtils::hash_password($password);
698
    my $digest = Koha::AuthUtils::hash_password($password);
716
- 

Return to bug 23865