AD 域賬號登錄


 

域服務數據讀寫,有倆種模式

1、輕量級的數據讀取

_domain是服務器的域名
獲取連接PrincipalContext pc = new PrincipalContext(ContextType.Domain, _domain)
驗證賬號密碼pc.ValidateCredentials(jobNumber, password)
引用System.DirectoryServices.AccountManagement命名空間后,按照如下如下方法,AD域驗證
    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, _domain))
    {
        // 工號一定要全
        using (var userPrincipal = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName,loginModel.JobNumber))
        {
            if (userPrincipal == null)
            {
                return "賬號不正確,請重新輸入";
            }
            if (!pc.ValidateCredentials(loginModel.JobNumber, loginModel.Password))
            {
                return @"密碼輸入錯誤,請重新輸入";
            }
            //GivenName是用戶名稱,Surname是工號(無前綴),Name是用戶名稱+工號(無前綴)
            PersonDetailInfo personDetailInfo = new PersonDetailInfo()
            {
                SearchName = userPrincipal.Name,
                UserName = userPrincipal.GivenName,
                JobNumber = userPrincipal.SamAccountName,
                EmailAddress = userPrincipal.EmailAddress
            };
            return personDetailInfo;
        }
    }

 2、DectoryEntry 

可以獲取整個服務器的數據,也可以修改其中的信息

參考類似文章:

http://www.it165.net/pro/html/201308/6829.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM