title: How to check if LDAP user exists/active?
body: <p>I am using C# application to authenticate and check Active Directory user which locates on a Window 2008 64 bit server.</p>
  
  <p>I was able to authenticate a user successfully when supplying the user name and password using the following code:  My domainName value is rootforest.com and my userName is admin6</p>
  
  <pre><code>        UserPrincipal usr;
          PrincipalContext ad;
  
          //Enter Active Directory settings
          ad = new PrincipalContext(ContextType.Domain, domainName,usrName,pswd);
  
          //search user
          usr = new UserPrincipal(ad);
          usr.SamAccountName = usrName;
  
          PrincipalSearcher search = new PrincipalSearcher(usr);
          usr = (UserPrincipal)search.FindOne();
          search.Dispose();
  </code></pre>
  
  <p>In another function where I want to check if user 'admin6' exists and I don't have the password, but when I check it the function keep throwing "Logon failire: unkoown user name or bad password. \r\n".  The code I used was almost identical to the above except this line:</p>
  
  <pre><code>        //Enter Active Directory settings
          ad = new PrincipalContext(ContextType.Domain, domainName);
  </code></pre>
  
  <p>Having this not working, I've tried other code I found on the web but they all give me the same error.  I begun to think it could be how I set up my Active Directory domain?</p>
  
  <p>The picture below is how my domain looks:</p>
  
  <p><a href="https://picasaweb.google.com/100922945973553878191/ActiveDirectory?authuser=0&amp;feat=directlink" rel="nofollow">https://picasaweb.google.com/100922945973553878191/ActiveDirectory?authuser=0&amp;feat=directlink</a>  </p>
  
  <p>Can anyone assist me with this? I've been stuck with this issue for last day or so now and I can't seem to find out why. If you have some codes I can try it would be great</p>