Well, since LDAP saves the data in a tree-like-structure, you'll need to know where a user is located to find his distinguishedName (= path and unique key to that user object).

If you save all your users in one container of the tree (Well, then you seem to loose the structure, but you can also save it as an attribute or referal to a department object...), e.g.

c=org co=MyCompany cn=Users cn=Mickey Mouse id456 cn=Donald Duck id123 cn=Tim Towdi id111

it becomes rather easy, then your distinguishedName (=dn) looks like

x) cn=Donald Duck id123,cn=Users,co=MyCompany,c=org x) cn=Mickey Mouse id456 ,cn=Users,co=MyCompany,c=org

then you can build your bindDn very easily (the id is here to get everything unique; if you use another way to make sure an object is unique); if not, you first have to do a search for it, e.g. by an anonymous bind, e.g.

use Net::LDAP; my $ldap = Net::LDAP->new($ldapServer) or die "Error: $@"; my $result = $ldap->bind(); # anonymous bind first die ("Error in bind: ", $result->error) if $result->code; $result = $ldap->search ( base => 'cn=Users,co=MyCompany,c=org', filter => "(&(sn=$surname)(givenName=$givenName))", # & is for an +AND scope => 'sub', # start from base and search to the bottom attributes => [] ); die ("Error in search: ", $result->error) if $result->code; foreach my $entry ($result->entries) { print "DN: ", $entry->dn(), "\n"; } } $ldap->unbind();

if you only get back one user, try to bind as this user and his password:

use Net::LDAP; my $ldap = Net::LDAP->new($ldapServer) or die "Error: $@"; my $success = $ldap->bind($dn, -password => $userPassword); if ($success->code) { print "Error\n"; } else { print "Ok\n"; $ldap->unbind(); }

the following perldoc's give you some code examples:

perldoc Net::LDAP::FAQ perldoc Net::LDAP::Examples

These codes are note tested, and maybe you need a completely different structure

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"


In reply to Re: verifification of LDAP credentials by strat
in thread verifification of LDAP credentials by kamesh3183

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.