AD 域賬號驗證
阿新 • • 發佈:2018-12-20
主要驗證程式碼如下:
/// <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; }