Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DirectoryServices UserPrincipal.SetPassword忽略密码策略(密码历史记录)_C#_Asp.net_Active Directory_Directoryservices - Fatal编程技术网

C# DirectoryServices UserPrincipal.SetPassword忽略密码策略(密码历史记录)

C# DirectoryServices UserPrincipal.SetPassword忽略密码策略(密码历史记录),c#,asp.net,active-directory,directoryservices,C#,Asp.net,Active Directory,Directoryservices,正如标题所示,在设置用户密码时,我遇到了一个关于遵守密码策略的问题,特别是密码历史限制 该场景是当用户不知道其当前密码时重置用户密码。我使用以下方法来实现这一点: using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "XXXX", "ADMINUSER", "ADMINPASSWORD")) { using (UserPrincipal user = UserPrincipal.FindBy

正如标题所示,在设置用户密码时,我遇到了一个关于遵守密码策略的问题,特别是密码历史限制

该场景是当用户不知道其当前密码时重置用户密码。我使用以下方法来实现这一点:

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "XXXX", "ADMINUSER", "ADMINPASSWORD")) {
    using (UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username)) {
        user.SetPassword(password);
    }
}
这适用于除密码历史记录限制之外的所有策略

现在,以这个场景为例,当用户想要更改其密码并且知道我正在使用的当前密码时:

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "XXXX.XXX.com")) {
    using (UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username)) {
        user.ChangePassword(currentPassword, newPassword);
    }
}
。。。它按预期工作,并根据所有密码策略限制进行验证

有没有人必须处理这件事


干杯:)

这是我用过的设计。SetPassword的作用类似于重置用户密码的管理员—复杂性策略适用,但对历史记录没有限制。假设管理员重置了您的密码,看到“无法设置相同的密码”-您的一个密码被泄露


我们的解决方法是允许管理层只检查我们的一个web子系统,并保留哈希的历史记录,以便将验证历史记录的责任放在自定义子系统而不是ad上。

如果通过FindByIdentity找不到用户名,您可能还需要先检查它是否为null

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "XXXX.XXX.com")) {
    using (UserPrincipal user = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, username))
    {
        if (user != null)
        {
            user.ChangePassword(currentPassword, newPassword);
        }
        else
        {
            throw new Exception(string.Format("Username not found: {0}", username));
        }
    }
}

我知道这是一个老帖子,但我们从未找到一个可以接受的答案。我们的系统人员不喜欢为历史存储我们自己的哈希值。我们最终实现了这样的解决方案:

using (PrincipalContext context = new PrincipalContext(ContextType.Domain, 
        "XXXX","ADMINUSER", "ADMINPASSWORD"))
{
    using (UserPrincipal user = 
        UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName, username)) 
    {
        string tempPassword = Guid.NewGuid().ToString();
        user.SetPassword(tempPassword);
        user.ChangePassword(tempPassword, password);
    }
}

我们将此人的密码重置为代码知道的足够长和复杂的随机密码。然后,我们使用用户输入的新密码在更改过程中将该密码用作旧密码。如果进程未通过包括密码历史记录在内的策略检查,我们将该错误传递回最终用户,他们必须重试。

我非常确定这是出于设计,如果没有其他方法绕过它,这是我计划的解决方法。谢谢你的快速洞察力:)好奇。我正在编写一些.net代码,创建新的域用户,这些域用户使用
UserPrincipal.SetPassword()
设置密码,当密码不满足域的密码复杂性要求时,调用
UserPrincipal.Save()
抛出一个
System.Runtime.InteropServices.comeException
,并显示一条消息,该消息声明
“密码不符合密码策略要求。请检查最小密码长度、密码复杂性和密码历史记录要求。(HRESULT的例外:0x800708C5)。
。疯狂的事情是,帐户仍然被创建@wiktor zychla I也面临同样的问题。然而,是否有任何关于这种行为的官方文件?只是想检查一下是否有任何Microsoft文档中提到过这一点?提前谢谢@普拉内:这一条明确表示感谢@Wiktor。在您提供的链接中,有一点是可以使用LDAP API应用历史检查。在目前的软件版本中,这是可能的吗?这篇文章似乎已经过时了。我只是在寻找一个密码重置功能的解决方案,以纪念.NETFramework 4.0+中的历史记录签入。再次感谢!