【问题标题】:"The specified network password is not correct." exception when changing a users password“指定的网络密码不正确。”更改用户密码时出现异常
【发布时间】:2016-05-03 05:45:41
【问题描述】:

我正在运行一个更改用户密码的 ASP.NET 应用程序。 PasswordException “指定的网络密码不正确。”每次调用 ChangePassword 方法时都会抛出异常,即使当前密码已经过验证。

如果我输入了无效的当前密码,则会引发异常。这是预期的结果。

如果我输入当前有效密码,则会引发异常,但密码仍然会更改(我已经测试过在更改后立即对其进行验证)。

代码很简单:

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() 无论如何都会抛出此异常。

标签: c# asp.net active-directory passwords


【解决方案1】:

微软有一个修复: http://support.microsoft.com/en-us/kb/3139921 用于 8.1/2012R2 和 http://support.microsoft.com/en-us/kb/3140410 7/2008R2。

这些补丁消除了删除旧更新的需要——到目前为止,我已经在 2 个案例中看到了这一点。

也就是说,Ben 是绝对正确的——根据您的系统,您可能还需要删除:

3135173 
3135174 
3126593
3126041 
3126587 
3126434 

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

看我的评论。

【讨论】:

【解决方案2】:

我有一个 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 安全公告MS16-014 中引用的所有补丁。安装 KB3126041 后,当用户尝试更改其密码时,将引发以下异常,但密码将成功更改。此外,用户将能够通过应用程序使用旧密码和新密码登录!

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,一切正常!

【讨论】:

    【解决方案3】:

    有一个类似的问题,并认为它与 MS16-014 https://support.microsoft.com/en-us/kb/3134228 有关 - 它确实在此 KB 中声明存在问题 - (“例如,当您尝试更改“域 B”时可能会出现问题来自加入“域 A”的计算机的密码,并且未配置从域 A 到域 B 的信任。”)但它被列为 kb3126041 的问题

    需要在我受影响的系统上删除以下更新

    kb3126593 kb3126587

    操作系统:Windows 2008 R2 SP1

    希望这会有所帮助。

    【讨论】:

    • 我们卸载了 kb3126593、kb3126587 和 KB3126041,它有所帮助! ASP.NET 更改密码功能再次起作用。谢谢!
    • @Ben 您是否从 DC 或加入域的计算机中删除了修补程序?我们目前在这个堆栈跟踪中遇到了几乎相同的问题,但是 KB 既没有安装在运行更改密码代码的机器上,也没有安装在 RODC 上。
    猜你喜欢
    • 2012-01-07
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-03
    • 2015-09-02
    • 2020-11-13
    • 2013-06-15
    相关资源
    最近更新 更多