Active Directory/Search for a user: Difference between revisions

Content added Content deleted
(added Perl programming solution)
Line 391: Line 391:
Surname: Milton
Surname: Milton
userID: jmilton
userID: jmilton
</pre>

=={{header|Perl}}==
{{Trans|Raku}}
<lang perl># 20210306 Perl programming solution

use strict;
use warnings;

use Net::LDAP;

my $ldap = Net::LDAP->new( 'ldap://ldap.forumsys.com' ) or die "$@";

my $mesg = $ldap->bind( "cn=read-only-admin,dc=example,dc=com",
password => "password" );
$mesg->code and die $mesg->error;

my $srch = $ldap->search( base => "dc=example,dc=com",
filter => "(|(uid=gauss))" );

$srch->code and die $srch->error;

foreach my $entry ($srch->entries) { $entry->dump }

$mesg = $ldap->unbind;</lang>
{{out}}
<pre>
------------------------------------------------------------------------
dn:uid=gauss,dc=example,dc=com

objectClass: inetOrgPerson
organizationalPerson
person
top
cn: Carl Friedrich Gauss
sn: Gauss
uid: gauss
mail: gauss@ldap.forumsys.com
</pre>
</pre>