Problem with ResetPassword - NullReferenceException

  • Thread starter Thread starter Bobby Edward
  • Start date Start date
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
 
Back
Top