perl AD Authentication code sample

use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_text ldap_error_name ldap_error_desc );

my $ldap = Net::LDAP->new('ad.ohio.edu', version => 3);
my $mesg = $ldap->start_tls(verify=>none);
my $mesg = $ldap->bind("CN=SERVICE_LOGIN,OU=Service Accounts,OU=OIT-SysOps,OU=OIT,OU=Ohio,DC=ohio,DC=edu",password=>SERVICE_PASSWORD,);
if ( $mesg->code ){
   my $errstr = $mesg->code;
   print "Service Login Error code:  $errstr\n";
   $errstr = ldap_error_text($errstr);
   print "$errstr\n";
   exit;
}

#NOW REBIND AND CHECK USERNAMANE AND PASSWORD
my $mesg = $ldap->bind("CN=FACULTY_LOGIN,OU=People,DC=ohio,DC=edu",password=>FACULTY_PASSWORD,);
if ( $mesg->code ){
   my $errstr = $mesg->code;
   print "Faculty Login Error code:  $errstr\n";
   $errstr = ldap_error_text($errstr);
   print "$errstr\n";
   exit;
}
Comments