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

(-)a/C4/ILSDI/Services.pm (-3 / +2 lines)
Lines 380-388 sub AuthenticatePatron { Link Here
380
    unless( $is_valid ) {
380
    unless( $is_valid ) {
381
        $response->{code} = 'PatronPasswordNotSecure';
381
        $response->{code} = 'PatronPasswordNotSecure';
382
        $response->{securePasswordLabel} = $error;
382
        $response->{securePasswordLabel} = $error;
383
        my $minPasswordLength = C4::Context->preference('minPasswordLength');
383
        my $minPasswordLength = C4::Context->preference('minPasswordLength') // 3;
384
        $response->{securePasswordPattern} = '.{'.$minPasswordLength.'}' if( $error eq 'too_short');
384
        $response->{securePasswordPattern} = Koha::AuthUtils::password_policy();
385
        $response->{securePasswordPattern} = '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{'.$minPasswordLength.'}' if( $error eq 'too_weak');
386
    }
385
    }
387
386
388
    return $response;
387
    return $response;
(-)a/Koha/AuthUtils.pm (+17 lines)
Lines 161-166 sub is_password_valid { Link Here
161
    return ( 1, undef );
161
    return ( 1, undef );
162
}
162
}
163
163
164
=head2 password_policy
165
166
my ( $regex) = password_policy();
167
168
return a regex matching the password policy in use
169
170
=cut
171
172
sub password_policy {
173
    my $minPasswordLength = C4::Context->preference('minPasswordLength');
174
    $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3;
175
    if ( C4::Context->preference('RequireStrongPassword') ) {
176
        return '(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{'.$minPasswordLength.'}';
177
    }
178
    return '.{'.$minPasswordLength.'}';
179
}
180
164
=head2 generate_password
181
=head2 generate_password
165
182
166
my password = generate_password();
183
my password = generate_password();
(-)a/t/db_dependent/ILSDI_Services.t (-2 / +5 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 10;
22
use Test::More tests => 11;
23
use Test::MockModule;
23
use Test::MockModule;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 44-49 subtest 'AuthenticatePatron test' => sub { Link Here
44
    $schema->storage->txn_begin;
44
    $schema->storage->txn_begin;
45
45
46
    my $plain_password = 'tomasito';
46
    my $plain_password = 'tomasito';
47
    t::lib::Mocks::mock_preference( 'minPasswordLength', 0 );
48
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
47
49
48
    $builder->build({
50
    $builder->build({
49
        source => 'Borrower',
51
        source => 'Borrower',
Lines 111-116 subtest 'AuthenticatePatron Secure Password test' => sub { Link Here
111
    $schema->storage->txn_begin;
113
    $schema->storage->txn_begin;
112
114
113
    my $plain_password = 'tomasito';
115
    my $plain_password = 'tomasito';
116
    t::lib::Mocks::mock_preference( 'minPasswordLength', 0 );
117
    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
114
118
115
    $builder->build({
119
    $builder->build({
116
        source => 'Borrower',
120
        source => 'Borrower',
117
- 

Return to bug 23011