title: How to Perform LDAP authentication in Perl
body: <p>I want to write <strong>LDAP authentication</strong> code for my <strong>Perl</strong> script.Below I have provided the sample USER details and AD server details.
  I am not able to authenticate the LDAP user with the variable provided below. 
  I am using <code>Net::LDAP</code> library but I am still not able to achieve my objective.
  I need help to understand LDAP authentication process and the logic I need to imply to authenticate an LDAP user.</p>
  
  <p>One doubt I have is "do i need to verify whether the LDAP user exist or not in the AD server or not?" </p>
  
  <pre><code>USER:cn=Feroz,dc=Alam,dc=com 
  PWD:nike 
  HOST:10.10.10.10 
  PORT:1234
  AD_USER:CN=Feroz,OU=Service,OU=Accounts,DC=Alam,DC=com
  AD_PWD:addidas
  AD_SERVER:myadserver.com
  $ldap = Net::LDAP-&gt;new($HOST, port=&gt;$PORT) or die "Cant Connect to LDAP server:$@";
  #IF I REMOVE THE PORT NO i AM GETTING THE ERROR "Cant Connect to LDAP server:IO::Socket::INET: connect:"
  if ( $ldap-&gt;bind($USER,password=&gt;$PWD) ) {
      print "Successful Authentication\n";
      #IT IS GIVING ME SUCCESSFUL AUTHENTICATION MESSAGE EVEN IF ENTER THE WRONG PASSWORD
  }
  else{
      print "Unsuccessful Authentication\n";
      push(@downlist, $server);
      --$upcount;
  }
  $ldap-&gt;unbind();
  
  DEBUG LOGS:
  Net::LDAP=HASH(0x488268) sending:
  Net::LDAP=HASH(0x488268) received:
  0000   12: SEQUENCE {
  0002    1:   INTEGER = 1
  0005    7:   [APPLICATION 1] {
  0007    1:     ENUM = 49
  000A    0:     STRING = ''
  000C    0:     STRING = ''
  000E     :   }
  000E     : }
  Successful Authentication
  Net::LDAP=HASH(0x488268) sending:
  </code></pre>
  
  <p>Please help......</p>