X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;ds=sidebyside;f=opac%2Fopac-passwd.pl;h=b5ae895947562929fbf4bbd106127595b93f2101;hb=d14ed73744fa23d4ed649da6d847f4b37cdfce92;hp=56e99675e4580cd68bfbf7c3a5e8d2dc598671fb;hpb=1b8f3194e9f616f46260c849eda5a9f6c717d5fa;p=koha_ffzg diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index 56e99675e4..b5ae895947 100755 --- a/opac/opac-passwd.pl +++ b/opac/opac-passwd.pl @@ -30,6 +30,7 @@ use C4::Circulation; use C4::Members; use C4::Output; use Koha::AuthUtils qw(hash_password); +use Koha::Patrons; my $query = new CGI; my $dbh = C4::Context->dbh; @@ -44,48 +45,47 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -# get borrower information .... -my ( $borr ) = GetMemberDetails( $borrowernumber ); -my $minpasslen = C4::Context->preference("minPasswordLength"); +my $patron = Koha::Patrons->find( $borrowernumber ); if ( C4::Context->preference("OpacPasswordChange") ) { my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?"); if ( $query->param('Oldkey') && $query->param('Newkey') && $query->param('Confirm') ) { + my $error; + my $new_password = $query->param('Newkey'); + my $confirm_password = $query->param('Confirm'); if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) ) { - if ( $query->param('Newkey') =~ m|^\s+| or $query->param('Newkey') =~ m|\s+$| ) { - $template->param( - Error_messages => 1, - PasswordContainsTrailingSpaces => 1, - ); - } - elsif ( $query->param('Newkey') eq $query->param('Confirm') - && length( $query->param('Confirm') ) >= $minpasslen ) - { # Record password - my $clave = hash_password( $query->param('Newkey') ); - $sth->execute( $clave, $borrowernumber ); - $template->param( 'password_updated' => '1' ); - $template->param( 'borrowernumber' => $borrowernumber ); - } - elsif ( $query->param('Newkey') ne $query->param('Confirm') ) { - $template->param( 'Ask_data' => '1' ); - $template->param( 'Error_messages' => '1' ); - $template->param( 'PassMismatch' => '1' ); - } - elsif ( length( $query->param('Confirm') ) < $minpasslen ) { + + if ( $new_password ne $confirm_password ) { $template->param( 'Ask_data' => '1' ); $template->param( 'Error_messages' => '1' ); - $template->param( 'ShortPass' => '1' ); - } - else { - $template->param( 'Error_messages' => '1' ); + $template->param( 'passwords_mismatch' => '1' ); + } else { + my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $new_password ); + unless ( $is_valid ) { + $error = 'password_too_short' if $error eq 'too_short'; + $error = 'password_too_weak' if $error eq 'too_weak'; + $error = 'password_has_whitespaces' if $error eq 'has_whitespaces'; + } else { + # Password is valid and match + my $clave = hash_password( $new_password ); + $sth->execute( $clave, $borrowernumber ); + $template->param( 'password_updated' => '1' ); + $template->param( 'borrowernumber' => $borrowernumber ); + } } } else { - $template->param( 'Ask_data' => '1' ); - $template->param( 'Error_messages' => '1' ); - $template->param( 'WrongPass' => '1' ); + $error = 'WrongPass'; + } + if ($error) { + $template->param( + Ask_data => 1, + Error_messages => 1, + $error => 1, + ); + } } else { @@ -104,13 +104,14 @@ if ( C4::Context->preference("OpacPasswordChange") ) { } } } -$template->param(firstname => $borr->{'firstname'}, - surname => $borr->{'surname'}, - minpasslen => $minpasslen, - passwdview => 1, +$template->param( + firstname => $patron->firstname, + surname => $patron->surname, + passwdview => 1, ); -output_html_with_http_headers $query, $cookie, $template->output; + +output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; sub goodkey { my ( $dbh, $borrowernumber, $key ) = @_;