2 # This script lets the users change the passwords by themselves.
4 # (c) 2005 Universidad ORT Uruguay.
6 # This file is part of the extensions and enhacments made to koha by Universidad ORT Uruguay
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use C4::Auth; # checkauth, getborrowernumber.
27 use Digest::MD5 qw(md5_base64);
31 use Koha::AuthUtils qw(hash_password);
35 my $dbh = C4::Context->dbh;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
39 template_name => "opac-passwd.tt",
47 my $patron = Koha::Patrons->find( $borrowernumber );
48 if ( C4::Context->preference("OpacPasswordChange") ) {
49 if ( $query->param('Oldkey')
50 && $query->param('Newkey')
51 && $query->param('Confirm') )
54 my $new_password = $query->param('Newkey');
55 my $confirm_password = $query->param('Confirm');
56 if ( C4::Auth::checkpw_hash( scalar $query->param('Oldkey'), $patron->password ) ) {
58 if ( $new_password ne $confirm_password ) {
59 $template->param( 'Ask_data' => '1' );
60 $template->param( 'Error_messages' => '1' );
61 $template->param( 'passwords_mismatch' => '1' );
63 my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $new_password );
64 unless ( $is_valid ) {
65 $error = 'password_too_short' if $error eq 'too_short';
66 $error = 'password_too_weak' if $error eq 'too_weak';
67 $error = 'password_has_whitespaces' if $error eq 'has_whitespaces';
69 # Password is valid and match
70 $patron->set_password( $new_password );
71 $template->param( 'password_updated' => '1' );
72 $template->param( 'borrowernumber' => $borrowernumber );
90 # Called Empty, Ask for data.
91 $template->param( 'Ask_data' => '1' );
92 if (!$query->param('Oldkey') && ($query->param('Newkey') || $query->param('Confirm'))){
93 # Old password is empty but one of the others isn't
94 $template->param( 'Error_messages' => '1' );
95 $template->param( 'WrongPass' => '1' );
97 elsif ($query->param('Oldkey') && (!$query->param('Newkey') || !$query->param('Confirm'))){
98 # Oldpassword is entered but one of the other fields is empty
99 $template->param( 'Error_messages' => '1' );
100 $template->param( 'PassMismatch' => '1' );
105 firstname => $patron->firstname,
106 surname => $patron->surname,
111 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };