Bugzilla – Attachment 94522 Details for
Bug 23865
Throw exceptions from Koha::AuthUtils::is_password_valid
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23865: Throw exceptions in Koha::AuthUtils::is_valid_password
Bug-23865-Throw-exceptions-in-KohaAuthUtilsisvalid.patch (text/plain), 2.96 KB, created by
Lari Taskula
on 2019-10-22 10:42:37 UTC
(
hide
)
Description:
Bug 23865: Throw exceptions in Koha::AuthUtils::is_valid_password
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2019-10-22 10:42:37 UTC
Size:
2.96 KB
patch
obsolete
>From 07c9264b7ad71630cc10e37aa2a2736981e09173 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Tue, 22 Oct 2019 10:36:35 +0000 >Subject: [PATCH] Bug 23865: Throw exceptions in > Koha::AuthUtils::is_valid_password > >Exceptions are currently thrown in Koha::Patron->set_password. > >We need to validate password (with exceptions) without wanting to set >the password. > >To test: >1. Make sure is_valid_password is not used anywhere in codebase apart from > Koha::Patron::set_password (grep -rn 'is_valid_password') >2. prove t/db_dependent/Koha/Patrons.t > Observe ok 35 - ->set_password >--- > Koha/AuthUtils.pm | 13 ++++++++++--- > Koha/Patron.pm | 17 ----------------- > 2 files changed, 10 insertions(+), 20 deletions(-) > >diff --git a/Koha/AuthUtils.pm b/Koha/AuthUtils.pm >index d834536357..6ec034415e 100644 >--- a/Koha/AuthUtils.pm >+++ b/Koha/AuthUtils.pm >@@ -151,13 +151,20 @@ sub is_password_valid { > my $minPasswordLength = C4::Context->preference('minPasswordLength'); > $minPasswordLength = 3 if not $minPasswordLength or $minPasswordLength < 3; > if ( length($password) < $minPasswordLength ) { >- return ( 0, 'too_short' ); >+ my $min_length = C4::Context->preference('minPasswordLength'); >+ $min_length = 3 if not $min_length or $min_length < 3; >+ >+ my $password_length = length($password); >+ Koha::Exceptions::Password::TooShort->throw( >+ length => $password_length, min_length => $min_length >+ ); > } > elsif ( C4::Context->preference('RequireStrongPassword') ) { >- return ( 0, 'too_weak' ) >+ Koha::Exceptions::Password::TooWeak->throw() > if $password !~ m|(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{$minPasswordLength,}|; > } >- return ( 0, 'has_whitespaces' ) if $password =~ m[^\s|\s$]; >+ Koha::Exceptions::Password::WhitespaceCharacters->throw() >+ if $password =~ m[^\s|\s$]; > return ( 1, undef ); > } > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index fca796ff28..12d123bee0 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -693,23 +693,6 @@ sub set_password { > > unless ( $args->{skip_validation} ) { > my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); >- >- if ( !$is_valid ) { >- if ( $error eq 'too_short' ) { >- my $min_length = C4::Context->preference('minPasswordLength'); >- $min_length = 3 if not $min_length or $min_length < 3; >- >- my $password_length = length($password); >- Koha::Exceptions::Password::TooShort->throw( >- length => $password_length, min_length => $min_length ); >- } >- elsif ( $error eq 'has_whitespaces' ) { >- Koha::Exceptions::Password::WhitespaceCharacters->throw(); >- } >- elsif ( $error eq 'too_weak' ) { >- Koha::Exceptions::Password::TooWeak->throw(); >- } >- } > } > > my $digest = Koha::AuthUtils::hash_password($password); >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23865
:
94522
|
94523