更改用户密码时出现“指定的网络密码不正确。”异常。

5
我正在运行一个ASP.NET应用程序,该应用程序更改用户的密码。每次调用ChangePassword方法时,都会抛出PasswordException“指定的网络密码不正确。”,即使当前密码已经通过验证也是如此。
如果我输入无效的当前密码,则会抛出异常。这是预期结果。
如果我输入有效的当前密码,则会抛出异常,但密码仍然被更改了(我已经在更改后立即测试过验证)。
代码非常简单:
var context = new PrincipalContext(ContextType.Domain, "domain.net");
var valid = context.ValidateCredentials(username, oldPassword);
var userPrincipal = UserPrincipal.FindByIdentity(context, username);
userPrincipal.ChangePassword(oldPassword, newPassword);

每次操作时,不管当前密码是否正确,都会导致抛出以下异常:

System.DirectoryServices.AccountManagement.PasswordException: The specified network password is not correct. (Exception from HRESULT: 0x80070056) ---> System.Runtime.InteropServices.COMException: The specified network password is not correct. (Exception from HRESULT: 0x80070056)
 --- End of inner exception stack trace ---
 at System.DirectoryServices.AccountManagement.SDSUtils.ChangePassword(DirectoryEntry de, String oldPassword, String newPassword)
 at System.DirectoryServices.AccountManagement.ADStoreCtx.ChangePassword(AuthenticablePrincipal p, String oldPassword, String newPassword)
 at StudentAccountManager.ChangeUserPassword(String username, String oldPassword, String newPassword)

有用的信息:

  • 托管网站的域名(例如webdomain.net)与更改密码所在的域不同。
  • domain.net中有三个域控制器,其中一个是只读的。
  • 两个域控制器位于现场。另一个在外场。PDC位于现场。
  • 如果在PrincipalContext中使用任何特定的域控制器(例如dc1.domain.net,dc2.domain.net),一切正常(已测试所有三个)。
  • 当在PrincipalContext中指定domain.net时,userPrincipal.SetPassword方法可以正确工作。
  • 运行应用程序池的用户帐户具有更改和设置domain.net上密码的权限
  • 域之间存在单向信任(domain.net信任webdomain.net)
  • Web服务器运行Windows Server 2012 R2,domain.net上的域控制器运行Windows Server 2008 R2

我最好的猜测是凭证验证和更改密码请求发送之间存在时间问题。可能新凭据正在被验证针对尚未收到更改密码请求的域控制器?这将导致抛出异常,但密码仍然会更改。


就我所知,我在Windows 10中遇到了这个问题,应用程序在Visual Studio本地运行。应用程序正在使用Windows身份验证,但是UserPrincipal.ChangePassword()仍然会抛出此异常。 - Ellesedil
3个回答

5

我曾经遇到过类似的问题, 并且认为这与MS16-014有关 https://support.microsoft.com/en-us/kb/3134228-实际上在这个KB中有一个问题--("例如, 当您尝试从加入了'域A'并且没有配置来自域A到域B的信任的计算机上更改您的'域B'密码时, 问题就会出现."),但它被列为kb3126041的问题

我的受影响系统需要卸载以下更新

kb3126593 kb3126587

操作系统: Windows 2008 R2 SP1

希望这能帮到您。


我们卸载了kb3126593、kb3126587和KB3126041,它帮助了!ASP.NET更改密码功能再次可用。谢谢! - Ross
@Ben,你是从DC还是加入域的机器上删除了热修复补丁?我们目前遇到了几乎相同的问题,但是KBs既没有安装在运行更改密码代码的机器上,也没有安装在RODC上。 - Peit

3
微软已经提供了解决方案:http://support.microsoft.com/en-us/kb/3139921(适用于8.1/2012R2)和http://support.microsoft.com/en-us/kb/3140410(适用于7/2008R2)。这些补丁程序消除了卸载旧更新的需要——迄今为止,我已经在两个案例中看到了这一点。但是,正如Ben所说,根据您的系统,您可能还需要删除以下内容:
3135173 
3135174 
3126593
3126041 
3126587 
3126434 

这些内容列在:https://support.microsoft.com/en-us/kb/3134228

请查看我的评论。


本文描述了我认为的同样的问题:https://social.technet.microsoft.com/Forums/office/en-US/a6d4b82f-9a32-4fee-aac5-b9c81f6c9c78/the-specified-network-password-is-not-correct-exception-from-hresult-0x80070056?forum=winserverDS 建议还应删除KB3132080。同一主题还提到https://support.microsoft.com/en-us/kb/3139921可能是8.1 / 2012R2的修复程序,然后阅读本文,我们将其视为7/2008R2的可能修复程序:https://support.microsoft.com/en-us/kb/3140410。我还没有能够测试这些修复程序。 - robertpb

1
我有一个Web应用程序服务器,它调用了System.DirectoryServices.AccountManagement.AuthenticablePrincipal对象上的ChangePassword方法。当前密码和新密码字段被正确填充并由经过身份验证的用户发送到ChangePassword方法中。
在我的情况下:
  • 我没有跨域;我的Web应用程序服务器在同一域中。
  • 我们有两个域控制器;都在本地网络上。
  • Web服务器正在运行Windows Server 2012 R2;我不确定域控制器的操作系统。
我的代码如下:
public bool ChangePassword(string username, string oldPassword, string newPassword, out ActiveDirectoryMembership.LogonError changePasswordLogonError)
{

    try
    {
        using (var context = new PrincipalContext(ContextType.Domain, DomainServer, _ldapUsername, _ldapPassword))
        {

            using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username))
            {
                user.ChangePassword(oldPassword, newPassword);
                changePasswordLogonError = ActiveDirectoryMembership.LogonError.LogonSuccessful;
                return true;
            }
        }

    }

    catch (PrincipalOperationException pex)
    {
        if ((ActiveDirectoryMembership.LogonError)(pex.ErrorCode) == ActiveDirectoryMembership.LogonError.AccountLockedOut)
        {
            changePasswordLogonError = ActiveDirectoryMembership.LogonError.AccountLockedOut;
            return false;
        }

        else
            throw;
    }
    catch (PasswordException pwdEx)
    {
        Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(pwdEx, Policies.WARNING_EXCEPTION_POLICY_NAME);

        //Look at the error message and attempt to parse out the HRESULT and map it to our LogonError enum
        //A complete list of Network Management Error codes is available here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa370674(v=vs.85).aspx
        //The HRESULT is a hex value which will need to be converted to an int in order to be matched against the list of Error code values
        if (pwdEx.Message.Contains("HRESULT: 0x80070056"))
            changePasswordLogonError = ActiveDirectoryMembership.LogonError.LogonFailure;
        else if (pwdEx.Message.Contains("HRESULT: 0x800708C5"))
            changePasswordLogonError = ActiveDirectoryMembership.LogonError.PasswordDoesNotMeetComplexityRequirements;
        else
            throw;

        return false;
    }
    catch (Exception)
    {
        throw;
    }

}

我的应用服务器已安装了Microsoft Security Bulletin MS16-014中提到的所有补丁。但是,当用户尝试更改密码时,将抛出以下异常,但密码仍然会成功更改。此外,用户可以通过应用程序使用旧密码和新密码进行登录!

Timestamp: 2016-03-08 12:39:55.033
Message: HandlingInstanceID: cd253adb-1e51-489a-8cf5-870568fb26ff
An exception of type 'System.DirectoryServices.AccountManagement.PasswordException' occurred and was caught.
------------------------------------------------------------------------------------------------------------
03/08/2016 12:39:54
Type : System.DirectoryServices.AccountManagement.PasswordException, System.DirectoryServices.AccountManagement, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The specified network password is not correct. (Exception from HRESULT: 0x80070056)
Source : System.DirectoryServices.AccountManagement
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ChangePassword(System.DirectoryServices.DirectoryEntry, System.String, System.String)
HResult : -2146233087
Stack Trace :    at System.DirectoryServices.AccountManagement.SDSUtils.ChangePassword(DirectoryEntry de, String oldPassword, String newPassword)
   at System.DirectoryServices.AccountManagement.ADStoreCtx.ChangePassword(AuthenticablePrincipal p, String oldPassword, String newPassword)
   at System.DirectoryServices.AccountManagement.PasswordInfo.ChangePassword(String oldPassword, String newPassword)
   at System.DirectoryServices.AccountManagement.AuthenticablePrincipal.ChangePassword(String oldPassword, String newPassword)
   at MyApplication.Web.UI.Infrastructure.ActiveDirectoryMembershipProvider.ChangePassword(String username, String oldPassword, String newPassword, LogonError& changePasswordLogonError)

Additional Info:

MachineName : SOME-SERVER
TimeStamp : 3/8/2016 5:39:55 PM
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null
AppDomainName : /LM/W3SVC/1/ROOT-3-131019323428219091
ThreadIdentity : 
WindowsIdentity : DOMAIN\App-Pool-Username
    Inner Exception
    ---------------
    Type : System.Runtime.InteropServices.COMException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : The specified network password is not correct. (Exception from HRESULT: 0x80070056)
    Source : 
    Help link : 
    ErrorCode : -2147024810
    Data : System.Collections.ListDictionaryInternal
    TargetSite : 
    HResult : -2147024810
    Stack Trace : The stack trace is unavailable.

我们从应用服务器中移除了KB3126041,一切都很好!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接