Problem with ResetPassword - NullReferenceException

B

Bobby Edward

I am writing code to reset a password, even if the current password is not
known. (This is for a site admin.) When I get to my ResetPassword line I
keep getting...

System.NullReferenceException: Object reference not set to an instance of an
object. at CoreLab.Common.Web.Providers.DbMembershipProvider.a(String A_0,
String A_1, Boolean A_2) at
CoreLab.Common.Web.Providers.DbMembershipProvider.ResetPassword(String
username, String answer) at
System.Web.Security.MembershipUser.ResetPassword(String passwordAnswer) at
System.Web.Security.MembershipUser.ResetPassword() at
admin_manageusers.cmdChgPwd_Click(Object sender, EventArgs e) in
F:\work-related\websites\1\admin\manageusers.aspx.vb:line 102

Any ideas why?

Here's the code...

Protected Sub cmdChgPwd_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdChgPwd.Click
Dim u As MembershipUser
Dim un As String =
GridView1.DataKeys(GridView1.SelectedIndex).Values("Username")

u = Membership.GetUser(un)

If u Is Nothing Then
lblStatus2.Text = "Username " & un & " not found!"
lblStatus2.ForeColor = Drawing.Color.Red
Return
End If

Dim autopassword As String = ""

Try
autopassword = u.ResetPassword()
Catch ex As Exception
lblStatus2.ForeColor = Drawing.Color.Red
lblStatus2.Text = "Error: " & ex.ToString
Return
End Try

Try
u.ChangePassword(autopassword, Me.txtNewPassword.Text)
Catch ex As Exception
lblStatus2.ForeColor = Drawing.Color.Red
lblStatus2.Text = "Error: " & ex.ToString
Return
End Try

lblStatus2.ForeColor = Drawing.Color.Green
lblStatus2.Text = "Password changed!"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top