对于未知用户,ValidateCredentials返回true?

Chr*_*s J 10 c# .net-4.0 active-directory

我在这里看到一些奇怪的行为PrincipalContext.ValidateCredentials.设置是父/子设置中的两个Active Directory域(因此我们有主域company.com和子域development.company.com).

当我针对主域验证凭据时,ValidateCredentials表现如预期,对于良好的用户/传递对返回true,对于其他任何对返回false.

但是,如果我在子域中验证用户,则ValidateCredentials对于良好的用户名/密码和无效用户都返回true.如果我向有效用户提供无效密码,则会正确返回false.

现在,我正在努力解决这个问题,UserPrincipal.FindByIdentity()如果用户存在,然后调用ValidateCredentials- 但我想知道发生了什么.

我看过的另一个解决方法是将用户名传递状态domain\usernameMSDN条目ValidateCredentials:

在此函数的每个版本中,userName字符串可以是各种不同格式之一.有关可接受格式类型的完整列表,请参阅ADS_NAME_TYPE_ENUM文档.

...列出了这种形式的用户名.但ValidateCredentials无论我传入的用户名和密码的组合如何,这都会导致始终返回true.

相关代码是:

bool authenticated = false;

// Various options tried for ContextOptions, [etc] inc. explicit username/password to bind to AD with -- no luck.
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domain, null, ContextOptions.Negotiate, null, null))
{
    log(pc.ConnectedServer + " => " + pc.UserName + " => " + pc.Name + " => " + pc.Container);
    using (var user = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, username))
    {
        if (user != null)
        {
            log(user.DistinguishedName + "; " + user.DisplayName);
            authenticated = pc.ValidateCredentials(username, password);
        } else {
            log("User not found");
            // Debug only -- is FindByIdentity() needed. This should always return 
            // false, but doesn't.
            authenticated = pc.ValidateCredentials(username, password);
        }
    }
}
return authenticated;
Run Code Online (Sandbox Code Playgroud)

任何和所有(明智的)建议都欢迎 - 我对此感到不安,因为它违背了所有期望.

我应该补充一下:这是我自己在我的机器上运行的,两者都是主域的成员.但是我也尝试在我的机器上的命令提示符中运行它作为子域(runas /user:subdomain\user cmd)的用户具有完全相同的结果.

Chr*_*s J 17

之后有一些谷歌搜索(不是我整天都在谷歌里试图找到这个),我找到了答案.

简而言之,如果在域中启用了Guest帐户,则ValidateCredentials将为未知用户返回TRUE.我刚刚在development.company.com上检查了来宾用户的状态,确定该帐户已启用.如果我禁用了来宾帐户,则ValidateCredentials会正确返回false.

这是一个相当基本的问题,不确定我是否热衷于这种行为......可惜它在MSDN上没有明确提到.

  • 为什么AD API必须如此大脑死亡? (3认同)