?
Solved

Change password login form not working

Posted on 2013-06-25
3
Medium Priority
?
418 Views
Last Modified: 2013-06-26
I am trying to create a change password form for users to change their passwords.
However, the following error is raised:
Object reference not set to an instance of an object.

The follow is the code attached to the update button

Dim connect As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
 "Data Source=\\IT\otusers.mdb"

        con.Open()
        str = "select * from login "
        com = New SqlCommand(str, con)
        Dim reader As SqlDataReader = com.ExecuteReader()
        While reader.Read()
            If OldPassword.Text = reader("Password").ToString() Then
                up = 1
            End If
        End While
        reader.Close()
        con.Close()
        If up = 1 Then
            con.Open()
            str = "UPDATE tblUsers SET Userpassword = '" + NewPassword.Text + "' WHERE username ='" + UserName.Text + "' "
            com = New SqlCommand(str, con)
            com.Parameters.Add(New SqlParameter("@Password", SqlDbType.VarChar, 50))
            com.Parameters("@Password").Value = NewPassword.Text
            com.ExecuteNonQuery()
            con.Close()
            Literal1.Text = "Password changed Successfully"
            Response.Redirect("MainMenu.aspx")
        Else
            Literal1.Text = "Please enter correct Current password"
        End If
    End Sub

Please assist
0
Comment
Question by:ernie_shah
3 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1500 total points
ID: 39276049
I suspect that following line is throwing the error

 If OldPassword.Text = reader("Password").ToString() Then

I would change your code

        con.Open()
        str = "select * from login "
        com = New SqlCommand(str, con)
        Dim reader As SqlDataReader = com.ExecuteReader()
        While reader.Read()
            If OldPassword.Text = reader("Password").ToString() Then
                up = 1
            End If
        End While
        reader.Close()
        con.Close()

Open in new window


to following


        con.Open()
        str = "select IsNull(Count(*), 0) from login Where UserName=@Username AND Password=@Password"
        com = New SqlCommand(str, con)
        com.Parameters.AddWithValue("@Username", Username.Text)
        com.Parameters.AddWithValue("@Password", OldPassword.Text
        up = com.ExecuteScalar()
        con.Close()

Open in new window

0
 
LVL 13

Expert Comment

by:Jitendra Patil
ID: 39277200
in which line of code you are getting this error?

please be advised that you need to have proper declaration of your variables.

hope this helps.
0
 

Author Comment

by:ernie_shah
ID: 39278240
The error is generated at con.open ()
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question