|
Lines 46-52
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
| 46 |
|
46 |
|
| 47 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
47 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
| 48 |
if ( C4::Context->preference("OpacPasswordChange") ) { |
48 |
if ( C4::Context->preference("OpacPasswordChange") ) { |
| 49 |
my $sth = $dbh->prepare("UPDATE borrowers SET password = ? WHERE borrowernumber=?"); |
|
|
| 50 |
if ( $query->param('Oldkey') |
49 |
if ( $query->param('Oldkey') |
| 51 |
&& $query->param('Newkey') |
50 |
&& $query->param('Newkey') |
| 52 |
&& $query->param('Confirm') ) |
51 |
&& $query->param('Confirm') ) |
|
Lines 54-60
if ( C4::Context->preference("OpacPasswordChange") ) {
Link Here
|
| 54 |
my $error; |
53 |
my $error; |
| 55 |
my $new_password = $query->param('Newkey'); |
54 |
my $new_password = $query->param('Newkey'); |
| 56 |
my $confirm_password = $query->param('Confirm'); |
55 |
my $confirm_password = $query->param('Confirm'); |
| 57 |
if ( goodkey( $dbh, $borrowernumber, $query->param('Oldkey') ) ) { |
56 |
if ( C4::Auth::checkpw_hash( scalar $query->param('Oldkey'), $patron->password ) ) { |
| 58 |
|
57 |
|
| 59 |
if ( $new_password ne $confirm_password ) { |
58 |
if ( $new_password ne $confirm_password ) { |
| 60 |
$template->param( 'Ask_data' => '1' ); |
59 |
$template->param( 'Ask_data' => '1' ); |
|
Lines 68-75
if ( C4::Context->preference("OpacPasswordChange") ) {
Link Here
|
| 68 |
$error = 'password_has_whitespaces' if $error eq 'has_whitespaces'; |
67 |
$error = 'password_has_whitespaces' if $error eq 'has_whitespaces'; |
| 69 |
} else { |
68 |
} else { |
| 70 |
# Password is valid and match |
69 |
# Password is valid and match |
| 71 |
my $clave = hash_password( $new_password ); |
70 |
$patron->set_password( $new_password ); |
| 72 |
$sth->execute( $clave, $borrowernumber ); |
|
|
| 73 |
$template->param( 'password_updated' => '1' ); |
71 |
$template->param( 'password_updated' => '1' ); |
| 74 |
$template->param( 'borrowernumber' => $borrowernumber ); |
72 |
$template->param( 'borrowernumber' => $borrowernumber ); |
| 75 |
} |
73 |
} |
|
Lines 111-133
$template->param(
Link Here
|
| 111 |
|
109 |
|
| 112 |
|
110 |
|
| 113 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
111 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
| 114 |
|
|
|
| 115 |
sub goodkey { |
| 116 |
my ( $dbh, $borrowernumber, $key ) = @_; |
| 117 |
|
| 118 |
my $sth = |
| 119 |
$dbh->prepare("SELECT password FROM borrowers WHERE borrowernumber=?"); |
| 120 |
$sth->execute($borrowernumber); |
| 121 |
if ( $sth->rows ) { |
| 122 |
my $hash; |
| 123 |
my ($stored_hash) = $sth->fetchrow; |
| 124 |
if ( substr($stored_hash,0,2) eq '$2') { |
| 125 |
$hash = hash_password($key, $stored_hash); |
| 126 |
} else { |
| 127 |
$hash = md5_base64($key); |
| 128 |
} |
| 129 |
if ( $hash eq $stored_hash ) { return 1; } |
| 130 |
else { return 0; } |
| 131 |
} |
| 132 |
else { return 0; } |
| 133 |
} |
| 134 |
- |