public static ADUserDetails AuthenticateUser(string userName, string password, string domain = DOMAINLDABNAME) { ADUserDetails result = null; try { DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, userName, password); object nativeObject = entry.NativeObject; result = ADUserDetails.GetADUserDetails(userName); } catch (DirectoryServicesCOMException) { } return(result); }
public static ADUserDetails GetADUserDetails(string userName, string domain = DOMAINLDABNAME) { ADUserDetails result = null; DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain); DirectorySearcher search = new DirectorySearcher(entry); search.Filter = "(&(objectClass=user)(objectCategory=person)(SAMAccountName=" + userName + "))"; SearchResult resultCol = search.FindOne(); if (resultCol != null) { result = ADUserDetails.GetUser(resultCol.Properties); } return(result); }