Samantha J T Star
Samantha J T Star

Reputation: 32838

Any way with the .NET membership in C# that I can reset a password

I am coding an application and I would like to give the admin a way to reset a password. The closest I have come to this is the following:

public abstract string ResetPassword(string username, string answer);

But this requires I know the answer.

With the .NET MembershipProvider how can I simply reset a password to something else? The only way I can think to do this is to delete the user and recreate.

Upvotes: 1

Views: 148

Answers (4)

Eric Brown - Cal
Eric Brown - Cal

Reputation: 14409

I wasn't able to do what you desire using only Membership... I had to use System.DirectoryServices.

Assuming you can get a Directory Entry, try this:

public void SetPassword( DirectoryEntry AdEntry, string userPassword )
        {
            ADEntry.Invoke( "SetPassword", new object[] { userPassword } );
            ADEntry.CommitChanges();
        }

If you need more help look here :

Howto: (Almost) Everything In Active Directory via C#

Upvotes: 0

Hector Correa
Hector Correa

Reputation: 26690

It's pretty easy to add the password recovery feature to an MVC project. I've got a blog post on my site where I detail the code that you need to add to your controller, model, and views:

http://hectorcorrea.com/Blog/Password-Recovery-in-an-ASP.NET-MVC-Project

Upvotes: 0

Arseny
Arseny

Reputation: 7361

Do you implement your custom MembershipProvider? if so set RequiresQuestionAndAnswer to false and you will not need to provide the answer in ResetPassword.

Upvotes: 1

Related Questions