private string AuthenticateUser(string username, string password, ref SearchResultEntry results) { string errorMessage = string.Empty; System.DirectoryServices.Protocols.LdapConnection ldapConnection = null; try { // Create the new LDAP connection LdapDirectoryIdentifier ldi = new LdapDirectoryIdentifier(Convert.ToString(CoreData.SnmpcToolkit.LdapServerIPAddress), 389); ldapConnection = new System.DirectoryServices.Protocols.LdapConnection(ldi); ldapConnection.AuthType = AuthType.Basic; NetworkCredential nc = new NetworkCredential("CN=" + username + "," + CoreData.SnmpcToolkit.LdapDistinguishedName, password); ldapConnection.Timeout = new TimeSpan(0, 0, 20); ldapConnection.Bind(nc); SearchRequest request = new SearchRequest(CoreData.SnmpcToolkit.LdapDistinguishedName, "(sAMAccountName=" + username + ")", System.DirectoryServices.Protocols.SearchScope.Subtree); SearchResponse response = (SearchResponse)ldapConnection.SendRequest(request); if (response.Entries.Count == 1) { results = response.Entries[0]; } } catch (Exception ex) { errorMessage = ex.Message; } return errorMessage; }