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

dde*_*ant 5 c# asp.net passwords active-directory

我正在运行一个更改用户密码的 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);
Run Code Online (Sandbox Code Playgroud)

这导致每次都抛出以下异常,无论当前密码是否正确:

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)
Run Code Online (Sandbox Code Playgroud)

有用的信息:

  • 网站所在的域(例如 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

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

小智 5

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

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

kb3126593 kb3126587

操作系统:Windows 2008 R2 SP1

希望这可以帮助。