Link to home
Start Free TrialLog in
Avatar of niravdesai23
niravdesai23

asked on

LDAP in C++

Hi,
I have PERL code for LDAP that take userid and password...and authenticate the user. Now I want to make the C++ code for the same. How can I make that?
Perl code:
#!usr/local/bin/perl      
use  Net::LDAP;
use Term::ReadKey;

$user= "";
$password= "";



print " Enter Username: ";
$user =<STDIN>;
chop($user);

print " Enter Password: ";
ReadMode('noecho');
$password = <STDIN>;
chop($password);
ReadMode('normal');


$LDAP_HOST            = 'ids.gm.com';
$LDAP_PORT            = 389;
$LDAP_BASE_DN             = 'ou=people,ou=intranet,dc=gm,dc=com';
$LDAP_USER_ATTRIBUTE      = 'gmguid';
$TRUE = 1;

# See if the Password is NULL
if(length($password)==0)
      {
      print "\nPassword field is left EMPTY.\n";
      }

#Establish a connection to the LDAP Server
my $ldap = new Net::LDAP($LDAP_HOST, port=>$LDAP_PORT, onerror=>'undef');
if(!$ldap)
      {
      # If the Connection is unsuccessful      
      print "\nConnection to LDAP Server is UNSUCCESFUL.\n";    
      }

#Validate the User ID and Get its Distinguished Name
my $dn = $LDAP_USER_ATTRIBUTE . '=' . $user . ',' . $LDAP_BASE_DN;
if(!$dn)
      {    
      # No Entry exists that matches $USERDN      
      print "\nInvalid USERID.\n";    
      }  

#Authenticate the User       
if (defined($ldap->bind($dn, password=>$password)))
      {
      print "\nUSER is AUTHINTICATED.\n";
      }
else
      {
      print "\nInvalid PASSWORD.\n";
      }
$ldap->unbind();
Avatar of niravdesai23
niravdesai23

ASKER

I increased the points....anybody with any clue on this...
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial