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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use C4::Auth; # checkauth, getborrowernumber.
27 use Digest::MD5 qw(md5_base64);
28 use C4::Circulation::Circ2;
30 use C4::Interface::CGI::Output;
33 my $dbh = C4::Context->dbh;
35 my ($template, $borrowernumber, $cookie)
36 = get_template_and_user({template_name => "opac-passwd.tmpl",
40 flagsrequired => {borrow => 1},
44 # get borrower information ....
45 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
46 my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?");
48 if ( $query->param('Oldkey') && $query->param('Newkey') && $query->param('Confirm') ){
49 if ( goodkey($dbh,$borrowernumber, $query->param('Oldkey')) ){
50 if ( $query->param('Newkey') eq $query->param('Confirm') &&
51 length($query->param('Confirm')) > 5 ){ # Record password
52 my $clave = md5_base64($query->param('Newkey'));
53 $sth->execute($clave,$borrowernumber);
54 $template->param('password_updated' => '1');
55 $template->param('borrowernumber' => $borrowernumber);
56 }elsif ( $query->param('Newkey') ne $query->param('Confirm') ){
57 $template->param('Ask_data' => '1');
58 $template->param('Error_messages' => '1');
59 $template->param('PassMismatch' => '1');
60 }elsif (length($query->param('Confirm')) <= 5 ){
61 $template->param('Ask_data' => '1');
62 $template->param('Error_messages' => '1');
63 $template->param('ShortPass' => '1');
65 $template->param('Error_messages' => '1');
68 $template->param('Ask_data' => '1');
69 $template->param('Error_messages' => '1');
70 $template->param('WrongPass' => '1');
73 # Called Empty, Ask for data.
74 $template->param('Ask_data' => '1');
76 output_html_with_http_headers $query, $cookie, $template->output;
80 my ($dbh, $borrowernumber, $key) = @_;
82 my $sth=$dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?");
83 $sth->execute($borrowernumber);
85 my ($md5password) = $sth->fetchrow;
86 if (md5_base64($key) eq $md5password) { return 1; } else { return 0; }