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 |
|