天天看點

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

作者:

唐宋元明清2188

出處:

http://www.cnblogs.com/kybs0/

本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須在文章頁面給出原文連接配接,否則保留追究法律責任的權利。

繼續閱讀