更改 Active Directory 密码
首先,请原谅我的英语,它不是我的母语。
我正在开发一个管理 Active Directory 的 Web 平台。我可以创建、删除和编辑组、用户、OU 等。
当连接的用户想要通过平台更改自己的密码时,会失败。
它来自DirectoryEntry.Invoke
。
我使用了DirectoryServices.DirectoryEntry
:
directoryEntry.Invoke("SetPassword", password);
directoryEntry.Commit();
所以我尝试了System.DirectoryServices.AccountManagement:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, Username);
user.SetPassword(password_);
user.Save();
不同的方式,同样的问题。
仅当用户尝试编辑自己的密码时,它才会失败。
任何帮助将不胜感激。
At first, please forgive my English, it is not my mother tongue.
I'm working on a web platform that manages Active Directory. I can create, delete and edit a group, user, OU, and so on.
When a connected user wants to change his own password with the platform, it fails.
It comes from DirectoryEntry.Invoke
.
I used the DirectoryServices.DirectoryEntry
:
directoryEntry.Invoke("SetPassword", password);
directoryEntry.Commit();
So I tried System.DirectoryServices.AccountManagement:
PrincipalContext ctx = new PrincipalContext(ContextType.Machine);
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, Username);
user.SetPassword(password_);
user.Save();
Different way, same problem.
It only fails when a user tries to edit his own password.
Any help would be grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
更改密码需要用户的旧密码才能设置新密码,重置密码需要重置密码的人员权限。在 AD 的默认权限下,只有管理员和帐户操作员可以重置密码。
Change Password requires user's old password to set new password and Reset password permission requires to the person who resets the password.With AD's default permissions, only Administrators and Account Operators can reset passwords.
试试这个代码。它对我有用,
Try this code. It works for me,
正如 Paolo 所指出的,如果没有额外的权限,您就无法调用“重置密码”。要调用 ChangePassword,您需要提供以前的密码,如下所示:
As Paolo notes, you can't call Reset Password without extra privileges. To call ChangePassword, you need to supply the previous password like this:
这是 Windows 的一项限制:用户无法重置自己的密码,即在不提供旧密码的情况下更改密码。
您只能更改您自己的密码,即提供旧密码和新密码。
尝试改用
ChangePassword
方法。This is a Windows restriction: a user cannot reset his own password, i.e. change the password without providing the old one.
You can only change your own password, i.e. provide old password and new password.
Try using the
ChangePassword
method instead.