Click here to Skip to main content
15,889,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..here i want to change my password.i have username,password,new password and confirm password are textboxes.after running the gm.i didn't get any error message but it doesn't update my database.here it is my code.so please help me.
C#
Imports System.Data.OleDb
Imports System.Data

Partial Class update
    Inherits System.Web.UI.Page
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim n As Integer
    Dim Adapte As OleDbDataAdapter = New OleDbDataAdapter

    Private Property txtnewpass As Object

    Private Property txtconfirmpass As Object

    Private Property txtuserid As Object

    Private Property txtoldpass As Object

    Private Property count As Integer

    Private Property newPass As Object

    Private Property ex As Exception

    Private Property username As String

    Private Property password As String

    Private Property conPass As Object

    Private Property this As Object

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            cn = New OleDbConnection("data source=C:\Users\Administrator\Desktop\login1.mdb;provider=Microsoft.Jet.OLEDB.4.0")
            cn.Open()

            username = TextBox1.Text
            password = TextBox2.Text
            newPass = TextBox3.Text
            conPass = TextBox4.Text


            cmd = New OleDbCommand("select username,password from login where username = @username and password = @password", cn)
            cmd.Parameters.AddWithValue("@username", this.TextBox1.Text)
            cmd.Parameters.AddWithValue("@password", this.TextBox2.Text)
            dr = cmd.ExecuteReader()
            dr.Read()

            If (dr("username").ToString() <> String.Empty & dr("password").ToString() <> String.Empty) Then


                If newPass.Trim() <> conPass.Trim() Then
                    Label5.Text = "New Password and old password does not match"
                End If
            Else
            End If

            cmd = New OleDbCommand("UPDATE login SET passwd = '" + TextBox3.Text + "' WHERE username ='" + TextBox1.Text + "'", cn)
            cmd.Parameters.AddWithValue("@newPasss", this.TextBox3.Text)
            cmd.Parameters.AddWithValue("@username", this.TextBox1.Text)
            cmd.Parameters.AddWithValue("@password", this.TextBox2.Text)

            Int(count = cmd.ExecuteNonQuery())
            If (count > 0) Then

                Label5.Text = "Password changed successfully"

            Else
            End If
            Label5.Text = "password not changed"
   
     Catch ex As Exception
       End Try     

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Session.Abandon()
        Response.Redirect("Login.aspx")
    End Sub
End Class
Posted
Updated 26-Dec-13 19:35pm
v3
Comments
Please debug and see where exactly is the Problem.
Member 10478580 27-Dec-13 2:36am    
there is no prob,it doent display any error msg,warngs etc..
King Fisher 27-Dec-13 1:44am    
debug it .you can find?
Member 10478580 27-Dec-13 2:38am    
yes idid.but it doent disply any error.when i enterd values after debugging,my db cant update those details
King Fisher 27-Dec-13 4:55am    
does it say this "password not changed"

1 solution

One Problem I can see

The Update query...
VB
cmd = New OleDbCommand("UPDATE login SET passwd = '" + TextBox3.Text + "' WHERE username ='" + TextBox1.Text + "'", cn)
cmd.Parameters.AddWithValue("@newPasss", this.TextBox3.Text)
cmd.Parameters.AddWithValue("@username", this.TextBox1.Text)
cmd.Parameters.AddWithValue("@password", this.TextBox2.Text)

should be like below...
C#
cmd = New OleDbCommand("UPDATE login SET passwd = @newPasss WHERE username = @username AND passwd = @password", cn)
cmd.Parameters.AddWithValue("@newPasss", newPass)
cmd.Parameters.AddWithValue("@username", username)
cmd.Parameters.AddWithValue("@password", password)

This will help you to restrict SQL Injection Attack.

But you should not directly store the Password, instead change your logic to implement some Encryption so that Password will be protected. Inserting plain text Password is not recommended.
 
Share this answer
 
v2
Comments
Member 10478580 27-Dec-13 2:35am    
thanku,still it doesn't work,no error msg displayed,and my db cant update the details.
What is the value of count in below line...

If (count > 0) Then
Label5.Text = "Password changed successfully"
Member 10478580 27-Dec-13 2:50am    
i'm assgned this value to the command
Member 10478580 27-Dec-13 2:51am    
Int(count = cmd.ExecuteNonQuery())
I am asking what is the value of count after you assign that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900