c# - PrincipalContext.ValidateCredentials 为空密码返回 true 是什么?

标签 c#

我们的应用程序有一个登录框,要求用户输入他们的 AD 凭据。我们获取这些凭据,然后调用

    using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, container, ContextOptions.SimpleBind))
    {
        return pc.ValidateCredentials(domain + @"\" + username, password, ContextOptions.SimpleBind);
    }

验证他们是否输入了有效的登录名/密码对。但我们发现,对 ValidateCredentials 的调用将返回 true 和空白密码,我们不知道为什么。无效的密码返回false,但是只要用户名正确,空白就会返回true。

最佳答案

来自 MSDN http://msdn.microsoft.com/en-us/library/bb154889.aspx

The ValidateCredentials method binds to the server specified in the constructor. If the username and password parameters are null, the credentials specified in the constructor are validated. If no credential were specified in the constructor, and the username and password parameters are null, this method validates the default credentials for the current principal.

在 PrincipalContext 构造函数中,您还可以指定要检查的凭据。

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, 
                       container, ContextOptions.SimpleBind, username, password))
{
    return pc.ValidateCredentials(domain + @"\" + username, password,
                                   ContextOptions.SimpleBind);
}

关于c# - PrincipalContext.ValidateCredentials 为空密码返回 true 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17794834/

相关文章:

c# - 如何在 C# 中执行超过 1 行的 sql 命令

c# - ScrollViewer 不适用于 wpf 中的网格

c# - Func<S, T> 的 T 仅在 S 和 T 不同时才从 lambda 表达式的输出中推断出来?

c# - Objective-C/iPhone 中的公钥加密

c# - SonarQube:无法为带有 <X 行的文件的文件的 X 行创建度量

c# - 二进制转整数的字符串

c# - Sitecore MVC Controller ActionResult 不在回发时呈现布局

c# - 在 C# 中使用 Web Client 时是否有上传限制?

c# - 抛出 HttpResponseException 总是导致 StatusCode : 500 response in the client

c# - 如何 try catch 未找到的程序集