using System.DirectoryServices;
using System.DirectoryServices.AccountManagement; using (DirectoryEntry adsEntry = new DirectoryEntry("LDAP://test.com", userName, password, AuthenticationTypes.Secure))
{
using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
{
adsSearcher.Filter = "(sAMAccountName=" + userName + ")";
try
{
SearchResult adsSearchResult = adsSearcher.FindOne();
}
catch (Exception ex)
{
// 用户名或密码错误
string strError = ex.Message;
}
finally
{
adsEntry.Close();
}
}
}
05-28 21:09