Search code examples
c#linqactive-directorywindows-authenticationlinq-to-ldap

Authenticate user using LinqtoLDAP


I'm using Linq to LDAP, and was wondering if there's a way to authenticate against the AD using Linq to LDAP,

Maybe something to the effect of this

var user = context.Query<User>().FirstOrDefault(u => u.SAMAccountName == "user123" && u.Password == "1234");

Solution

  • Passwords cannot be returned by a search in AD. You are only allowed to modify them over SSL. You can try to issue a Bind request using an LdapConnection, but that doesn't require LINQ to LDAP, only SYstem.DirectoryServices.Protocols.

    var connection = new LdapConnection("localhost");
    
    try
    {
        connection.Bind(new NetworkCredential("username", "password", "domain"));
    }
    catch (LdapException ex)
    {
    
    }
    

    Is there a reason why you can't use NTLM or Kerberos?