主要验证代码如下:
/// <summary>
/// LoginAD
/// </summary>
/// <param name="UserID"></param>
/// <param name="Pwd"></param>
/// <param name="domainName"></param>
/// <param name="error"></param>
/// <returns></returns>
private bool LoginAD(string UserID, string Pwd, string domainName, out string error)
{
error = "";
//return true; //%%Should be removed for production
bool success = false;
string path = "LDAP://" + domainName;
error = "";
System.DirectoryServices.DirectoryEntry Entry = new System.DirectoryServices.DirectoryEntry(path, UserID, Pwd);
System.DirectoryServices.DirectorySearcher Searcher = new System.DirectoryServices.DirectorySearcher(Entry);
Searcher.SearchScope = System.DirectoryServices.SearchScope.OneLevel;
try
{
System.DirectoryServices.SearchResult Results = Searcher.FindOne();
success = (Results != null);
}
catch (Exception e)
{
success = false;
error = e.Message;
//For error log
//BLL.INTLog.instance.AddSystemLog(Utility.TLPEnum.eLogType.ErrorLog, Utility.TLPEnum.eActionType.Login, UsrSession.FuncID, actDtl: e.Message, actBy: UsrSession.ActLoginID);
}
return success;
}