title: How to connect LDAP server with username and password?
body: <p>When I use <code>AuthenticationTypes.Anonymous</code> to connect to LDAP server, it`s ok:</p>
  
  <pre><code>var a = new DirectoryEntry("LDAP://localhost:389/dc=maxcrc,dc=com", "", "", AuthenticationTypes.Anonymous);
  </code></pre>
  
  <p>but when I want to use username and password to connect the server:</p>
  
  <pre><code>var a = new DirectoryEntry("LDAP://localhost:389/dc=maxcrc,dc=com", "cn=Manager,dc=maxcrc,dc=com", "111111"); 
  </code></pre>
  
  <p>it causes a "Specifying an invalid dn syntax" error:</p>
  
  <p><a href="https://i.stack.imgur.com/82uxs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/82uxs.png" alt="enter image description here"></a></p>
  
  <p>If I use this:</p>
  
  <pre><code>var a = new DirectoryEntry("LDAP://localhost:389/dc=moe,dc=com", "cn=Manager,dc=moe,dc=com", "111111", AuthenticationTypes.Encryption);
  </code></pre>
  
  <p>it causes an "The server is not operational" error:</p>
  
  <p><a href="https://i.stack.imgur.com/cMuiQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cMuiQ.png" alt="enter image description here"></a></p>
  
  <p>So how can I connect to my LDAP server with username and password?</p>