Solved

Change password login form not working

Posted on 2013-06-25
3
401 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 500 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 12

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now