title: AD on Windows Server 2012 + Windows LDAP + PHP Bind
body: <p>I've set up Active Directory and ADLDAP on Windows server 2012.  I'm trying a simple ldap_bind but continue to have a "invalid credentials" error spit back to me.</p>
  
  <p>In my AD Users and Groups screen, I clearly see the domain I made along with the OU (organizational unit) and users inside of it. ASDI Edit clearly tells me the DN for that user:</p>
  
  <pre><code>CN=Bob Smith,OU=Accounting,DC=mydomain,DC=net
  </code></pre>
  
  <p>Further, the BaseDN is clearly told to me in ASDI Edit because it's above the OU group "accounting" - </p>
  
  <pre><code>DC=mydomain,DC=net
  </code></pre>
  
  <p>Now onto my script - which throws no LDAP connect errors, only on bind, with a constant invalid credentials:</p>
  
  <pre><code>$connectionLDAP = "LDAP://localhost:54126"; 
  $basedn = 'DC=mydomain,DC=net';
  $ldap = ldap_connect($connectionLDAP) or die("Could not connect to LDAP server.");
  $username = $post['username'];
  $password = $post['password'];
  $usernameForBind = "CN=".$username.",OU=Accounting,".$basedn;
  ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  $bind = ldap_bind($ldap, $usernameForBind, $password);
  </code></pre>
  
  <p>This spits the following warning, and of course my script ends there since there is no positive match to username and password found:</p>
  
  <pre><code>Warning: ldap_bind(): Unable to bind to server: Invalid credentials in C:\....\login.php on line 41
  </code></pre>
  
  <p>And the below error echos produce this:</p>
  
  <pre><code>echo(ldap_error($ldap)."&lt;br&gt;");
  echo(ldap_errno($ldap)."&lt;br&gt;");
  
  
  Invalid credentials
  49
  </code></pre>
  
  <p>I have tried every combination of DN, username, email address, mydomain\username without the rest of the DN info, everything I can think of....but for the life of me it won't take, and google + Stack searches unfortunately aren't helping me at the moment get past this. </p>
  
  <p>Thanks for any assistance.</p>