public static bool VerifyUser(string username, string pwd)
{
string path;
path = "LDAP://OU=Users,OU=,OU=,DC=,DC=";
bool bRet = false;
DirectoryEntry de = new DirectoryEntry(path, username.ToLower(), pwd, AuthenticationTypes.Secure);
de.Username = username;
de.Password = pwd;
//密码经过散列
string strSearch = "(SAMAccountName=" + username + ")";
DirectorySearcher deSearcher = new DirectorySearcher(de, strSearch);
deSearcher.SearchScope = SearchScope.Subtree;
try
{
SearchResult sr = deSearcher.FindOne();
bRet = true;
}
catch (System.Exception ex)
{
Console.WriteLine(ex.Message);
}
return bRet;
}
转载于:https://www.cnblogs.com/viewcozy/p/3328261.html