AD 域賬號驗證

主要驗證代碼如下:

	    /// <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;
        }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章