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 264-307
sub exists_local {
Link Here
|
264 |
} |
265 |
} |
265 |
|
266 |
|
266 |
sub _do_changepassword { |
267 |
sub _do_changepassword { |
267 |
my ($userid, $borrowerid, $digest) = @_; |
268 |
my ($userid, $borrowerid, $password) = @_; |
|
|
269 |
|
270 |
my $digest = hash_password($password); |
271 |
|
268 |
$debug and print STDERR "changing local password for borrowernumber=$borrowerid to '$digest'\n"; |
272 |
$debug and print STDERR "changing local password for borrowernumber=$borrowerid to '$digest'\n"; |
269 |
changepassword($userid, $borrowerid, $digest); |
273 |
changepassword($userid, $borrowerid, $digest); |
270 |
|
274 |
|
271 |
# Confirm changes |
275 |
my ($ok, $cardnum) = checkpw_internal(C4::Context->dbh, $userid, $password); |
272 |
my $sth = C4::Context->dbh->prepare("SELECT password,cardnumber FROM borrowers WHERE borrowernumber=? "); |
276 |
return $cardnum if $ok; |
273 |
$sth->execute($borrowerid); |
277 |
|
274 |
if ($sth->rows) { |
278 |
warn "Password mismatch after update to borrowernumber=$borrowerid"; |
275 |
my ($md5password, $cardnum) = $sth->fetchrow; |
279 |
return; |
276 |
($digest eq $md5password) and return $cardnum; |
|
|
277 |
warn "Password mismatch after update to cardnumber=$cardnum (borrowernumber=$borrowerid)"; |
278 |
return; |
279 |
} |
280 |
die "Unexpected error after password update to userid/borrowernumber: $userid / $borrowerid."; |
281 |
} |
280 |
} |
282 |
|
281 |
|
283 |
sub update_local { |
282 |
sub update_local { |
284 |
my $userid = shift or return; |
283 |
my $userid = shift or croak "No userid"; |
285 |
my $digest = md5_base64(shift) or return; |
284 |
my $password = shift or croak "No password"; |
286 |
my $borrowerid = shift or return; |
285 |
my $borrowerid = shift or croak "No borrowerid"; |
287 |
my $borrower = shift or return; |
286 |
my $borrower = shift or croak "No borrower record"; |
288 |
my @keys = keys %$borrower; |
287 |
|
289 |
my $dbh = C4::Context->dbh; |
288 |
my @keys = keys %$borrower; |
290 |
my $query = "UPDATE borrowers\nSET " . |
289 |
my $dbh = C4::Context->dbh; |
291 |
join(',', map {"$_=?"} @keys) . |
290 |
my $query = "UPDATE borrowers\nSET " . |
292 |
"\nWHERE borrowernumber=? "; |
291 |
join(',', map {"$_=?"} @keys) . |
293 |
my $sth = $dbh->prepare($query); |
292 |
"\nWHERE borrowernumber=? "; |
294 |
if ($debug) { |
293 |
my $sth = $dbh->prepare($query); |
295 |
print STDERR $query, "\n", |
294 |
if ($debug) { |
296 |
join "\n", map {"$_ = '" . $borrower->{$_} . "'"} @keys; |
295 |
print STDERR $query, "\n", |
297 |
print STDERR "\nuserid = $userid\n"; |
296 |
join "\n", map {"$_ = '" . $borrower->{$_} . "'"} @keys; |
298 |
} |
297 |
print STDERR "\nuserid = $userid\n"; |
299 |
$sth->execute( |
298 |
} |
300 |
((map {$borrower->{$_}} @keys), $borrowerid) |
299 |
$sth->execute( |
301 |
); |
300 |
((map {$borrower->{$_}} @keys), $borrowerid) |
|
|
301 |
); |
302 |
|
302 |
|
303 |
# MODIFY PASSWORD/LOGIN |
303 |
# MODIFY PASSWORD/LOGIN |
304 |
_do_changepassword($userid, $borrowerid, $digest); |
304 |
_do_changepassword($userid, $borrowerid, $password); |
305 |
} |
305 |
} |
306 |
|
306 |
|
307 |
1; |
307 |
1; |
308 |
- |
|
|