tags:

views:

71

answers:

3

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();
+4  A: 

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.

jim
i get this error when i call Membership.GetUser(username);
what's the error?
jim
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 5123 and the SqlException message is: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\APP_DATA\ASPNETDB_TMP.MDF'.CREATE DATABASE failed. Some file names listed could not be created. Check related errors.Creating the ASPNETDB_1f5ebd767bfd48a9b513cf18197b312d database...
but you can create users, return a list of users and iterate over them? You only see an error when you're trying to reset a users password? InstallCommon.sql installs membership related services and if you're already up and running, you shouldn't see it. Do you have read/write permission on the app_data folder?
jim
+2  A: 

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); 
BrokenGlass
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 5123 and the SqlException message is: CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\APP_DATA\ASPNETDB_TMP.MDF'. CREATE DATABASE failed. Some file names listed could not be created. Check related errors. Creating the ASPNETDB_1f5ebd767bfd48a9b513cf18197b312d database...
happens when u call Membership.GetUser() function
A: 

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();

`