• 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

  • 相关阅读:
    田忌赛马 题解
    亚历山大的丢番图方程 题解
    zhx's contest题解
    芝麻OI比赛T7edges题解
    CSP-J2020游记
    Linux shell 学习笔记(五)
    Linux shell 学习笔记(四)
    Linux shell 学习笔记(三)
    Linux shell 学习笔记(二)
    Oracle并发
  • 原文地址:https://www.cnblogs.com/kybs0/p/5767255.html
Copyright © 2020-2023  润新知