Tuesday, May 18, 2010

Hard reset password on asp.net membership provider (applied to DNN)

I just moved a DNN (DotNetNuke) installation from a computer to another and restored the database in order to be able to work locally. DNN uses asp.net Membership as its default security provider thus I could not login to the web site (all passwords are encrypted using the local machine key). In order to override the password I wrote the following lines of code:
Dim mu As MembershipUser = Membership.GetUser("MyUserName")
mu.ChangePassword(mu.ResetPassword(), "mytoughpassword")
In the default page’s init event. This is the way to programmatically change any membership account’s password.

Happy coding and don't forget to delete the above mentioned lines after reseting the passwords!

1 comment:

Chris Carter said...

Thanks! Saved me a headache this morning.