【问题标题】:Authentication against Active Directory.. Necessity of DirectorySearcher针对 Active Directory 的身份验证.. DirectorySearcher 的必要性
【发布时间】:2018-08-06 08:06:24
【问题描述】:

我有以下代码来针对 Active Directory 验证给定的用户名和密码

DirectoryEntry entryInAbsg = new DirectoryEntry("LDAP://....../DC=....,DC=..", username, password,AuthenticationTypes.Secure);
            object nativeObject = entryInAbsg.NativeObject;
            authenticated = true;

这足以验证用户吗?我需要使用 DirectorySearcher 再次搜索用户吗? 上面的用户名和密码应该是Admin账号?

【问题讨论】:

    标签: authentication active-directory ldap


    【解决方案1】:

    这足以验证用户。但是要执行搜索,您需要创建一个 DirectorySeacher 实例并将您的 DirectoryEntry 对象 (entryinAbsg) 以及您可能想要的任何过滤器传递给构造函数。考虑下面的 C# 示例;

    private DirectorySeacher GetDirectorySeacher(DirectoryEntry entryInAbsg)
    {
          DirectorySearcher dirSeach = null;
          if(dirSearch == null)
          {
              try
              {
                  dirSearch = new DirectorySeacher(entryInAbsg)
              }
              catch (DirectoryServicesCOMException e)
              {
                  MessageBox.Show("Authentification Failed!!!, Please Check.", "Error Info", MessageBoxButtons.OK,MessageBoxIcon.Error);
              }
              return dirSearch;
         }
         else
         {
              return dirSearch;
         }
    }
    

    您可以根据自己的具体需求进行定制。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多