对于空白密码,PrincipalContext.ValidateCredentials返回true是什么?

时间:2013-07-22 18:32:30

标签: 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。

1 个答案:

答案 0 :(得分:4)

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

  

ValidateCredentials方法绑定到构造函数中指定的服务器。如果username和password参数为null,则验证构造函数中指定的凭据。如果构造函数中未指定凭证,并且username和password参数为null,则此方法将验证当前主体的默认凭据。

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

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