title: C# netcore ldap authentication using Novell.Directory.Ldap.NETStandard library
body: <p>it is the first time I'm working with LDAP and Active Directory. I have to make a web api with .NetCore that have to authenticate with ActiveDirectory (WindowsServer 2008 r2), I'm following the samples in  <a href="https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/tree/master/original_samples/Samples" rel="nofollow noreferrer">Novell.Directory.Ldap.NETStandard</a> but i can't understand the way that I must set the parameters.
  This is the users that I created in ActiveDirectory Server:</p>
  
  <p><a href="https://i.stack.imgur.com/A7iGq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A7iGq.jpg" alt="https://i.stack.imgur.com/A7iGq.jpg"></a></p>
  
  <p>In Novell's samples</p>
  
  <pre><code>if (args.Length != 5)
  {
      System.Console.Out.WriteLine("Usage:   mono VerifyPassword &lt;host name&gt;" + " &lt;login dn&gt; &lt;password&gt; &lt;object dn&gt;\n" + "         &lt;test password&gt;");
      System.Console.Out.WriteLine("Example: mono VerifyPassword Acme.com " + "\"cn=Admin,o=Acme\" secret\n" + "         \"cn=JSmith,ou=Sales,o=Acme\" testPassword");
      System.Environment.Exit(0);
  }
  
  int ldapPort = LdapConnection.DEFAULT_PORT;
  int ldapVersion = LdapConnection.Ldap_V3;
  System.String ldapHost = args[0];
  System.String loginDN = args[1];
  System.String password = args[2];
  System.String objectDN = args[3];
  System.String testPassword = args[4];
  LdapConnection conn = new LdapConnection();
  
  try
  {
      // connect to the server
      conn.Connect(ldapHost, ldapPort);
  
      // authenticate to the server
      conn.Bind(ldapVersion, loginDN, password);
  
      LdapAttribute attr = new LdapAttribute("userPassword", testPassword);
      bool correct = conn.Compare(objectDN, attr);
  
      System.Console.Out.WriteLine(correct?"The password is correct.":"The password is incorrect.\n");
  
      // disconnect with the server
      conn.Disconnect();
  }
  </code></pre>
  
  <p>In Novell's samples the "user" parameters looks like this "ou=sales,o=Acme", so I was trying:</p>
  
  <pre><code>int ldapPort = LdapConnection.DEFAULT_PORT;
  int ldapVersion = LdapConnection.Ldap_V3;
  bool compareResults = false;
  String ldapHost = "192.168.58.251";
  String loginDN = @"cn=jperez";
  String password1 = "Jperez123";
  String dn = "mydn";
  LdapConnection lc = new LdapConnection();
  LdapAttribute attr = null;
  
  try
  {
      // connect to the server
      lc.Connect(ldapHost, ldapPort);
      var sdn = lc.GetSchemaDN();
  
      // authenticate to the server
      lc.Bind(ldapVersion, loginDN, password1);
  
      ...
  }
  catch (LdapException e)
  {
      Console.WriteLine("Error: " + e.ToString());
  }
  </code></pre>
  
  <p>But I get this error:
  LDAP: </p>
  
  <blockquote>
    <p>LdapException: Invalid Credentials (49) Invalid Credentials
    LdapException: Server Message: 80090308: LdapErr: DSID-0C0903A8,
    comment: AcceptSecurityContext error, data 52e, v1db1\u0000
    LdapException: Matched DN:</p>
  </blockquote>
  
  <p>I also get the schemaDn with this funciton: <code>lc.GetSchemaDN()</code>, that return this result:  <code>CN=Aggregate,CN=Schema,CN=Configuration,DC=mydn,DC=local</code></p>
  
  <p>After googling there is no much information with <code>.Netcore</code> than the <code>Novell's samples</code>, please I need your help.</p>