user175084
user175084

Reputation: 4640

reset user password

I have a server which has machines...

I have an administrator and multiple users... these are all windows users and not present in the databse.

How do i reset the user password.... i log in using the administrator and provide the username that needs to be reset..

I tried

 string newPassword;

 u = Membership.GetUser(UsernameTextBox.Text, false);

but this does not work...

any suggestions... thanks

Code to add users:

 DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
            DirectoryEntry NewUser = AD.Children.Add(username, "user");
            NewUser.Invoke("SetPassword", new object[] { password });
            NewUser.Invoke("Put", new object[] { "Description", description });
            NewUser.CommitChanges();

Upvotes: 1

Views: 2432

Answers (3)

user175084
user175084

Reputation: 4640

I got it done by this methid.. it works thanks for the answers though

DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry HostedUser = AD.Children.Find(hostedUserName, "user");

string password = new HostedGuiAddMachines().CreateRandomPassword(8);
HostedUser.Invoke("SetPassword", new object[] { password });
HostedUser.Close();
AD.Close();

Upvotes: -1

jim
jim

Reputation: 27426

try this

string username = "user";
string password = "newpassword";
MembershipUser mu = Membership.GetUser(username);
mu.ChangePassword(mu.ResetPassword(), password);

if you have in your web.config requiresQuestionAnswer="true", you will get an error when you try and reset the password.

Upvotes: 5

BrokenGlass
BrokenGlass

Reputation: 161002

You are probably looking for the ResetPassword method. To reset to a known password you can use something like this:

MembershipUser currentUser = Membership.GetUser(user_name);
bool bPasswordChanged = false;
bPasswordChanged = currentUser.ChangePassword(currentUser.ResetPassword(), new_password); 

Upvotes: 2

Related Questions