【发布时间】:2021-02-25 16:59:13
【问题描述】:
我希望有人可以向我解释这一点,因为我正在努力解决我遇到的问题。
我收到的错误是“对象已经存在”。每当我尝试运行我们的 ResetPassword 函数时。奇怪的是,如果用户帐户之前已重置密码,我只会收到此错误。如果我使用新密码创建一个新帐户,或者在数据库中搜索尚未对其帐户调用 ResetPassword 函数的用户,那么它将让我调用该函数一次。注意:在这一次它让我运行密码确实被重置的功能。任何已经运行过ResetPassword的账号都会提示对象已经存在的错误。
public static void ResetPassword(DirectoryEntry User, string password)
{
User.Invoke("SetPassword", new object[] { password });
User.Properties["LockOutTime"].Value = 0x0000; //unlock account
int val = (int)User.Properties["userAccountControl"].Value;
User.Properties["userAccountControl"].Value = val & ~0x2; //Enable account
User.CommitChanges();
Logs.CreateLogEntry("Reset password", User);
User.Close();
}
如您所见,我们传入了一个 DirectoryEntry 用户,以及一个生成的新密码。我们在 IIS 网站的后端使用匿名登录来获得足够高的管理员凭据以使用 SetPassword。
【问题讨论】:
标签: c# asp.net active-directory