Bugzilla – Attachment 83595 Details for
Bug 22047
set_password should have a 'skip_validation' param
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22047: Add 'skip_validation' param to Koha::Patron->set_password
Bug-22047-Add-skipvalidation-param-to-KohaPatron-s.patch (text/plain), 3.43 KB, created by
Josef Moravec
on 2019-01-02 20:05:29 UTC
(
hide
)
Description:
Bug 22047: Add 'skip_validation' param to Koha::Patron->set_password
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2019-01-02 20:05:29 UTC
Size:
3.43 KB
patch
obsolete
>From 1acae7f85e5c643041db96a391fa3b20165aaa78 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Wed, 26 Dec 2018 12:37:07 -0300 >Subject: [PATCH] Bug 22047: Add 'skip_validation' param to > Koha::Patron->set_password > >This patch makes Koha::Patron->set_password expect a hashref as param >and adds support for an 'skip_validation' param to be passed. Its purpose is to >make the method skip the relevant password strength checks if required. > >It targets the Auth_with_ldap.pm usage when the 'update_password' flag >is set in the configuration. > >The tests on this bug cover this use case so, to test: > >- Apply the tests patch >- Run: > $ kshell > k$ prove t/db_dependent/Koha/Patrons.t >=> FAIL: Tests fail, code doesn't work as expected >- Apply this patch >- Run: > k$ prove t/db_dependent/Koha/Patrons.t >=> SUCCESS: Tests pass! Yay! >- Sign off :-D > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Patron.pm | 38 ++++++++++++++++++++++---------------- > 1 file changed, 22 insertions(+), 16 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 5831034..b10b116 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -670,13 +670,15 @@ sub update_password { > > =head3 set_password > >- $patron->set_password( $plain_text_password ); >+ $patron->set_password({ password => $plain_text_password [, skip_validation => 1 ] }); > > Set the patron's password. > > =head4 Exceptions > > The passed string is validated against the current password enforcement policy. >+Validation can be skipped by passing the I<skip_validation> parameter. >+ > Exceptions are thrown if the password is not good enough. > > =over 4 >@@ -692,24 +694,28 @@ Exceptions are thrown if the password is not good enough. > =cut > > sub set_password { >- my ( $self, $password ) = @_; >+ my ( $self, $args ) = @_; > >- my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); >+ my $password = $args->{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; >+ unless ( $args->{skip_validation} ) { >+ my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password ); > >- 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(); >+ 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(); >+ } > } > } > >-- >2.1.4
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 22047
:
83491
|
83492
|
83493
|
83582
|
83583
|
83584
|
83594
|
83595
|
83596
|
84422
|
84423
|
84424