by Rusty Swayne 26.March 2008 15:41
I have been a huge fan of the provider model that ships with ASP.NET from the start. I especially love the ASP.NET Membership provider as it has saved me literally days of time coding and recoding user management functionality --- over and over and over. You get the point.
However, I had never found a way to quickly set a password for a user other than having the membership provider “reset” the password and send it to the user in an email which is really frustrating (both for me and the user especially since nine times out of ten the recipient of the email never changes their password to something they can remember and wind up asking you to reset it again).
The good news is it is easy to implement, although I admit it my current method seems sort of hacky and I am always on the lookout for a better solution.
Dim User as MembershipUser = GetMembershipUserToUpdate() ' not shown
Try
Dim tempPassword As String = User.ResetPassword()
If User.ChangePassword(tempPassword, txt_password.Text) Then
litMessage.Text = "Password changed successfully"
Else
litMessage.Text = "Failed to change password."
End If
Catch ex As Exception
litMessage.Text = ex.Message
End Try
Obviously, txt_password is an ASP.NET Textbox Control and litMessage is an ASP.NET Literal Control. If anyone has a nicer solution, it would be great to talk shop!
I posted the source code for a user control (adminSetUserPassword.ascx) here if you are interested.