Lines 19-25
package C4::Auth_with_ldap;
Link Here
|
19 |
|
19 |
|
20 |
use strict; |
20 |
use strict; |
21 |
#use warnings; FIXME - Bug 2505 |
21 |
#use warnings; FIXME - Bug 2505 |
22 |
use Digest::MD5 qw(md5_base64); |
22 |
use Carp; |
23 |
|
23 |
|
24 |
use C4::Debug; |
24 |
use C4::Debug; |
25 |
use C4::Context; |
25 |
use C4::Context; |
Lines 27-32
use C4::Members qw(AddMember changepassword);
Link Here
|
27 |
use C4::Members::Attributes; |
27 |
use C4::Members::Attributes; |
28 |
use C4::Members::AttributeTypes; |
28 |
use C4::Members::AttributeTypes; |
29 |
use C4::Utils qw( :all ); |
29 |
use C4::Utils qw( :all ); |
|
|
30 |
use C4::Auth qw(hash_password checkpw_internal); |
30 |
use List::MoreUtils qw( any ); |
31 |
use List::MoreUtils qw( any ); |
31 |
use Net::LDAP; |
32 |
use Net::LDAP; |
32 |
use Net::LDAP::Filter; |
33 |
use Net::LDAP::Filter; |
Lines 260-303
sub exists_local {
Link Here
|
260 |
} |
261 |
} |
261 |
|
262 |
|
262 |
sub _do_changepassword { |
263 |
sub _do_changepassword { |
263 |
my ($userid, $borrowerid, $digest) = @_; |
264 |
my ($userid, $borrowerid, $password) = @_; |
|
|
265 |
|
266 |
my $digest = hash_password($password); |
267 |
|
264 |
$debug and print STDERR "changing local password for borrowernumber=$borrowerid to '$digest'\n"; |
268 |
$debug and print STDERR "changing local password for borrowernumber=$borrowerid to '$digest'\n"; |
265 |
changepassword($userid, $borrowerid, $digest); |
269 |
changepassword($userid, $borrowerid, $digest); |
266 |
|
270 |
|
267 |
# Confirm changes |
271 |
my ($ok, $cardnum) = checkpw_internal(C4::Context->dbh, $userid, $password); |
268 |
my $sth = C4::Context->dbh->prepare("SELECT password,cardnumber FROM borrowers WHERE borrowernumber=? "); |
272 |
return $cardnum if $ok; |
269 |
$sth->execute($borrowerid); |
273 |
|
270 |
if ($sth->rows) { |
274 |
warn "Password mismatch after update to borrowernumber=$borrowerid"; |
271 |
my ($md5password, $cardnum) = $sth->fetchrow; |
275 |
return; |
272 |
($digest eq $md5password) and return $cardnum; |
|
|
273 |
warn "Password mismatch after update to cardnumber=$cardnum (borrowernumber=$borrowerid)"; |
274 |
return; |
275 |
} |
276 |
die "Unexpected error after password update to userid/borrowernumber: $userid / $borrowerid."; |
277 |
} |
276 |
} |
278 |
|
277 |
|
279 |
sub update_local { |
278 |
sub update_local { |
280 |
my $userid = shift or return; |
279 |
my $userid = shift or croak "No userid"; |
281 |
my $digest = md5_base64(shift) or return; |
280 |
my $password = shift or croak "No password"; |
282 |
my $borrowerid = shift or return; |
281 |
my $borrowerid = shift or croak "No borrowerid"; |
283 |
my $borrower = shift or return; |
282 |
my $borrower = shift or croak "No borrower record"; |
284 |
my @keys = keys %$borrower; |
283 |
|
285 |
my $dbh = C4::Context->dbh; |
284 |
my @keys = keys %$borrower; |
286 |
my $query = "UPDATE borrowers\nSET " . |
285 |
my $dbh = C4::Context->dbh; |
287 |
join(',', map {"$_=?"} @keys) . |
286 |
my $query = "UPDATE borrowers\nSET " . |
288 |
"\nWHERE borrowernumber=? "; |
287 |
join(',', map {"$_=?"} @keys) . |
289 |
my $sth = $dbh->prepare($query); |
288 |
"\nWHERE borrowernumber=? "; |
290 |
if ($debug) { |
289 |
my $sth = $dbh->prepare($query); |
291 |
print STDERR $query, "\n", |
290 |
if ($debug) { |
292 |
join "\n", map {"$_ = '" . $borrower->{$_} . "'"} @keys; |
291 |
print STDERR $query, "\n", |
293 |
print STDERR "\nuserid = $userid\n"; |
292 |
join "\n", map {"$_ = '" . $borrower->{$_} . "'"} @keys; |
294 |
} |
293 |
print STDERR "\nuserid = $userid\n"; |
295 |
$sth->execute( |
294 |
} |
296 |
((map {$borrower->{$_}} @keys), $borrowerid) |
295 |
$sth->execute( |
297 |
); |
296 |
((map {$borrower->{$_}} @keys), $borrowerid) |
|
|
297 |
); |
298 |
|
298 |
|
299 |
# MODIFY PASSWORD/LOGIN |
299 |
# MODIFY PASSWORD/LOGIN |
300 |
_do_changepassword($userid, $borrowerid, $digest); |
300 |
_do_changepassword($userid, $borrowerid, $password); |
301 |
} |
301 |
} |
302 |
|
302 |
|
303 |
1; |
303 |
1; |
304 |
- |
|
|