如何更改活动目录密码 [英] how can change active directory password
问题描述
当我尝试添加新用户然后成功创建用户时,我在该页面上都有一个网页,但是当尝试重置其密码时却出现错误.
成功添加新用户
Hi,
I have a web page through this page when I try to add a new user then users created successfully but when try resetting their password then I am getting errors’
add New user successfully
public static void AddUser(ADUser adUser)
{
// Local variables
DirectoryEntry oDE = null;
DirectoryEntry oDENewUser = null;
DirectoryEntries oDEs = null;
try
{
oDE = GetDirectoryEntry(GetADPath(PROD, adUser.UserType));
// 1. Create user account
oDEs = oDE.Children;
oDENewUser = oDEs.Add("CN=" + adUser.UserName, "user");
// 2. Set properties
SetProperty(oDENewUser, "givenName", adUser.FirstName);
SetProperty(oDENewUser, "sn", adUser.LastName);
SetProperty(oDENewUser, "mail", adUser.Email);
SetProperty(oDENewUser, "sAMAccountName", adUser.UserName);
oDENewUser.CommitChanges();
/// 4. Enable account
EnableAccount(oDENewUser);
// 3. Set password
//SetPassword(oDENewUser, adUser.Password);
SetPassword1(oDENewUser.Path, adUser.Password);
oDENewUser.CommitChanges();
oDENewUser.Close();
oDE.Close();
}
catch (Exception ex)
{
throw ex;
}
}
我尝试了以下2种SetPassword方法,但出现错误.
方法1.
I have try the following 2 SetPassword methods but getting error.
Method 1.
internal static void SetPassword1(string path, string userPassword)
{
//Local variables
DirectoryEntry usr = null;
try
{
usr = new DirectoryEntry();
usr.Path = path;
usr.AuthenticationType = AuthenticationTypes.Secure;
object ret = usr.Invoke("SetPassword", userPassword);
usr.CommitChanges();
usr.Close();
}
catch (Exception ex)
{
throw ex;
}
}
引发的异常(错误代码80072035:服务器不愿意处理请求)
方法2.
The exception raised (Error Code 80072035: The server is unwilling to process the request)
Method 2.
internal static void SetPassword(DirectoryEntry de, string userPassword)
{
//Local variables
//DirectoryEntry usr = null;
string quotePwd;
byte[] pwdBin;
try
{
quotePwd = String.Format(@"""{0}""", userPassword);
pwdBin = System.Text.Encoding.Unicode.GetBytes(quotePwd);
de.Properties["unicodePwd"].Value = pwdBin;
de.CommitChanges();
//usr.Close();
}
catch (Exception ex)
{
throw ex;
}
}
引发的异常("异常已由调用的目标引发.")
有没有一种简单的方法可以告诉您更改密码是否存在问题?
请尽快回复我.
谢谢.
The exception raised ("Exception has been thrown by the target of an invocation.")
Is there an easy way to tell if there is a problem with changing a password?
Please reply me as soon as possible.
Thanks.
推荐答案
如果我正确阅读了此内容,则说明您没有更改密码...新帐户没有可用的更改. :)
无论如何,要创建密码,您需要在具有管理员权限的帐户下运行.希望IIS/asp.net帐户没有它们,因此您需要设置用户&密码以及AuthenticationTypes.确保您已经拥有.
坦白地说,您最好只创建一个帐户,让Windows首次登录时要求用户输入密码.
参见此处: http://www.codeproject.com/KB/system/everythingInAD.aspx#40a [^ ]
此处 http://www.primaryobjects.com/CMS/Article66.aspx [
If I''m reading this correctly, you''re not changing the password...a new account doesn''t have one to change. :)
Anyway, to create a password you need to run under an account with admin privileges. Hopefully, the IIS/asp.net account doesn''t have them, so you''ll need to set user & password along with the AuthenticationTypes.Secure you already have.
Honestly, you''re probably better off just creating the account and have Windows ask the user for a password the first time they log on.
See here: http://www.codeproject.com/KB/system/everythingInAD.aspx#40a[^]
and here http://www.primaryobjects.com/CMS/Article66.aspx[^]
这篇关于如何更改活动目录密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!