【问题标题】:Custom Multi-factor Active Directory Authentication自定义多因素 Active Directory 身份验证
【发布时间】:2013-04-16 12:18:41
【问题描述】:

首先我会说我不知道​​我想要的东西是否真的可以完成。如果是这样,请不要犹豫,告诉我我在做梦。

我想在 C# 中创建一个自定义活动目录“身份验证器”。我的意思是,我希望每当有人登录时,首先检查他们存储在 AD 中的密码,然后执行第二步身份验证。只有两个步骤都通过了,用户才能登录。

现在,如果我想将此身份验证器集成到定制产品中,我想上述内容并不太牵强,对吧?我是否还想知道这个身份验证器是否可以在登录 Windows 本身时使用?或者可能是针对 AD 进行身份验证的预先存在的产品?

如果我不是在做梦,是否还有人知道任何好的文章/API 可以让我继续前进? API 不一定是免费的,因为我愿意拿出一些现金让事情进展得更快。

【问题讨论】:

  • Microsoft Active Directory 是您计划集成的唯一目录服务吗?
  • 这是迄今为止我唯一提到的一个,所以我要说是的。

标签: c# .net windows active-directory


【解决方案1】:

这是完全可行的。但是我想指出,在将服务器绑定到 Active Directory 时,您正在检查提供的用户名(通常是 sAMAccountName)和在一个操作中输入的密码。在 C# 中有几种方法可以做到这一点,但很多人(包括我自己)选择使用 System.DirectoryServicesSystem.DirectoryServices.Protocols 命名空间。

这就是我当前将用户绑定到 Active Directory 的方式,然后根据此方法的结果,我要么显示授权失败的原因,要么允许他们继续使用他们在应用程序中的帐户。

//Define your connection
LdapConnection ldapConnection = new LdapConnection("123.456.789.10:389");

try
{
      //Authenticate the username and password
      using (ldapConnection)
      {
          //Pass in the network creds, and the domain.
          var networkCredential = new NetworkCredential(Username, Password, Domain);
          //Since we're using unsecured port 389, set to false. If using port 636 over SSL, set this to true.
          ldapConnection.SessionOptions.SecureSocketLayer = false;
          ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
          //To force NTLM\Kerberos use AuthType.Negotiate, for non-TLS and unsecured, use AuthType.Basic
          ldapConnection.AuthType = AuthType.Basic;
          ldapConnection.Bind(networkCredential);
      }
      catch (LdapException ldapException)
      {
          //Authentication failed, exception will dictate why
      }
}

如果您还想更进一步并检索有关此用户的属性,check out this thread here

另外,我强烈推荐 Softerra 的 LDAP 浏览器来测试任何与 LDAP 相关的东西——它是一个很棒的产品,而且它是免费的。你可以download it from here.

希望这能让你朝着正确的方向前进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 2015-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多