removed incorrect module import
[koha.git] / opac / opac-passwd.pl
blob491cce03cc8f17d8fed8d904adb90806882ad11b
1 #!/usr/bin/perl
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
11 # version.
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
21 use strict;
23 use CGI;
25 use C4::Auth; # checkauth, getborrowernumber.
26 use C4::Context;
27 use Digest::MD5 qw(md5_base64);
28 use C4::Circulation;
29 use C4::Members;
30 use C4::Output;
32 my $query = new CGI;
33 my $dbh = C4::Context->dbh;
35 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37 template_name => "opac-passwd.tmpl",
38 query => $query,
39 type => "opac",
40 authnotrequired => 0,
41 flagsrequired => { borrow => 1 },
42 debug => 1,
46 # get borrower information ....
47 my ( $borr ) = GetMemberDetails( $borrowernumber );
48 my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?");
49 my $minpasslen = C4::Context->preference("minPasswordLength");
50 if ( $query->param('Oldkey')
51 && $query->param('Newkey')
52 && $query->param('Confirm') )
54 if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) ) {
55 if ( $query->param('Newkey') eq $query->param('Confirm')
56 && length( $query->param('Confirm') ) >= $minpasslen )
57 { # Record password
58 my $clave = md5_base64( $query->param('Newkey') );
59 $sth->execute( $clave, $borrowernumber );
60 $template->param( 'password_updated' => '1' );
61 $template->param( 'borrowernumber' => $borrowernumber );
63 elsif ( $query->param('Newkey') ne $query->param('Confirm') ) {
64 $template->param( 'Ask_data' => '1' );
65 $template->param( 'Error_messages' => '1' );
66 $template->param( 'PassMismatch' => '1' );
68 elsif ( length( $query->param('Confirm') ) < $minpasslen ) {
69 $template->param( 'Ask_data' => '1' );
70 $template->param( 'Error_messages' => '1' );
71 $template->param( 'ShortPass' => '1' );
73 else {
74 $template->param( 'Error_messages' => '1' );
77 else {
78 $template->param( 'Ask_data' => '1' );
79 $template->param( 'Error_messages' => '1' );
80 $template->param( 'WrongPass' => '1' );
83 else {
85 # Called Empty, Ask for data.
86 $template->param( 'Ask_data' => '1' );
87 if (!$query->param('Oldkey') && ($query->param('Newkey') || $query->param('Confirm'))){
88 # Old password is empty but one of the others isnt
89 $template->param( 'Error_messages' => '1' );
90 $template->param( 'WrongPass' => '1' );
92 elsif ($query->param('Oldkey') && (!$query->param('Newkey') || !$query->param('Confirm'))){
93 # Oldpassword is entered but one of the other fields is empty
94 $template->param( 'Error_messages' => '1' );
95 $template->param( 'PassMismatch' => '1' );
99 $template->param(firstname => $borr->{'firstname'},
100 surname => $borr->{'surname'},
101 minpasslen => $minpasslen,
102 passwdview => 1,
105 output_html_with_http_headers $query, $cookie, $template->output;
107 sub goodkey {
108 my ( $dbh, $borrowernumber, $key ) = @_;
110 my $sth =
111 $dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?");
112 $sth->execute($borrowernumber);
113 if ( $sth->rows ) {
114 my ($md5password) = $sth->fetchrow;
115 if ( md5_base64($key) eq $md5password ) { return 1; }
116 else { return 0; }
118 else { return 0; }