Browse Source

+ LDV::LDAP->auth

master
Alex 'AdUser' Z 10 years ago
parent
commit
632513fbd9
  1. 21
      lib/LDV/LDAP.pm

21
lib/LDV/LDAP.pm

@ -52,6 +52,19 @@ sub _filter_username {
]}, 'Net::LDAP::Filter'); ]}, 'Net::LDAP::Filter');
}; };
sub auth {
my ($self, $uid, $pass) = @_;
return unless ($uid and $pass);
my $dn = $self->_uid_to_dn($uid);
my $conn = Net::LDAP->new($self->{server}, onerror => sub { return shift });
my $result = $conn->bind($dn, password => $pass);
$conn->unbind;
$conn->disconnect;
return if $result->code;
return 1;
}
sub create { sub create {
my ($self, $uid) = @_; my ($self, $uid) = @_;
my $conn = $self->_connect(); my $conn = $self->_connect();
@ -165,6 +178,14 @@ LDV::LDAP -- ldap routines
* userbase -- where to search for users, (like dc=example,dc=com, default: unset) * userbase -- where to search for users, (like dc=example,dc=com, default: unset)
* userfilter -- objects that pass the filter, considered as users (default : "(class=InetOrgPerson)" * userfilter -- objects that pass the filter, considered as users (default : "(class=InetOrgPerson)"
=head2 C<auth>
my $ldap = LDV::LDAP->new(\%opts);
my $result = $ldap->auth($username, $password);
Check user/pass pair against ldap server.
Returns 1 on success or undef on auth failure/error;
=head2 C<create> =head2 C<create>
my $ldap = LDV::LDAP->new(\%opts); my $ldap = LDV::LDAP->new(\%opts);

Loading…
Cancel
Save