1

我在 LDAP 服务器上有一些嵌套组,并且这些组中有用户。如何通过仅在组(而不是整个域)中搜索来验证具有给定用户名和密码的用户?绑定会这样做吗?

4

1 回答 1

1

正如您在此问题的评论部分中所确认的,您所说的 LDAP 服务器是 Active Directory 服务器。所以,我的答案是基于这个关于如何针对 Active Directory 验证用户名和密码的著名答案,除了我根据您的要求进行了修改以限制搜索范围。

如果您使用 .NET 3.5 或更高版本,则可以使用System.DirectoryServices.AccountManagement命名空间的PrincipalContext 构造函数(ContextType、String、String)并轻松验证您的凭据:

// create a "principal context"
using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOUR.DOMAIN",
             "OU=Where,OU=You,OU=Wanna,OU=Search,DC=YOUR,DC=DOMAIN"))
   // change your container to a base OU where all your users are located.
{
    // validate the credentials
    bool isValid = pc.ValidateCredentials("myuser", "mypassword");
}
于 2018-07-10T13:04:27.677 回答