title: Active Directory authentication with Codeigniter Library
body: <p>I am using the ldap library for Codeigniter written by Greg Wojtak from <a href="http://www.techrockdo.com/projects/auth_ldap" rel="nofollow noreferrer">auth_ldap_library</a>.</p>
  
  <p>I have setup the config as per the instructions. However when i try to authenticate using my username and password i am getting an error (ldap_bind() unable to bind).</p>
  
  <p>Below is the config</p>
  
  <pre><code>$config['ldap_uri'] = array('ldaps://dc1.mycompany.com/', 'ldaps://dc2.mycompany.com/');
  $config['use_tls'] = false;  // Using SSL above, don't use TLS with it
  $config['search_base'] = 'DC=mycompany,DC=com';
  $config['user_search_base'] = 'CN=Users,DC=mycompany,DC=com';
  $config['group_search_base'] = 'CN=Users,DC=mycompany,DC=com';
  $config['user_object_class'] = 'user';
  $config['group_object_class'] = 'group';
  $config['user_search_filter'] = '';
  $config['group_search_filter'] = '';
  $config['login_attribute'] = 'sAMAccountName';
  $config['schema_type'] = 'ad'; // Could also use rfc2307bis
  $config['proxy_user'] = '';  // Or CN=ProxyUser,CN=Users,DC=mycompany,DC=com
  $config['proxy_pass'] = '';
  $config['roles'] = array(1 =&gt; 'User', 
                      3 =&gt; 'Power User',
                      5 =&gt; 'Administrator');
  $config['auditlog'] = 'application/logs/audit.log';
  </code></pre>
  
  <p>This is the line where iam getting the error "error looking up DN for username"</p>
  
  <p>line 217 is the foreach line</p>
  
  <pre><code>   foreach($this-&gt;user_search_base as $usb) {
     $search = ldap_search($this-&gt;ldapconn, $usb, $filter, 
              array('dn', $this-&gt;login_attribute, 'cn'));
          $entries = ldap_get_entries($this-&gt;ldapconn, $search);
          if(isset($entries[0]['dn'])) {
              $binddn = $entries[0]['dn'];
              break;
          }
      }
  </code></pre>
  
  <p>Error message is as below.</p>
  
  <p><img src="https://i.stack.imgur.com/yE0Ch.jpg" alt="Error Message"></p>
  
  <p>Has anyone encountered a similar issue?</p>