I'm a newbie in vb. My first project is a grading system for a certain school. In my login form, there's a Forgot Password button. In the Forgot Password form, the user is asked to answer a secret question that he filled up upon registration, and if the answer is correct it will lead him to a Change Password form. My problem is, I don't know how to get then delete and then replace the password of a certain user. I attached some screen shots of my work. Please someone help me.. Thank you..

Attachments 1.jpg 25.7 KB
5 Years
Discussion Span
Last Post by MarkGia

You can do like this if user gives correct answer of that secret question you can show a message box saying your password is....

or you can use following code but in place of old password use the result of your secret answer...

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        If txtNew.TextLength < 5 Then
            MsgBox("The New Password Should be of Atleast 5 Characters")
            txtNew.Text = ""
            txtRe.Text = ""
        ElseIf txtOld.Text = txtNew.Text Then
            MsgBox("The New Password is Same As Old Password")
            txtNew.Text = ""
        ElseIf (txtNew.Text = txtRe.Text) Then

                Dim con As New SqlConnection("Data Source=XXXX-578AC20261\SQLEXPRESS;Initial Catalog=TT;Integrated Security=True")
                Dim ds1 As New DataSet
                Dim da1 As New SqlDataAdapter("select * from Login where UserName='" & Trim(txtUserName.Text) & "'and Password='" & Trim(txtOld.Text) & "'", con)

                If da1.Fill(ds1) Then

                    Dim ra As Integer
                    Dim cb As SqlClient.SqlCommand
                    cb = New SqlClient.SqlCommand("Update Login Set password='" + txtNew.Text + "' where UserName='" + txtUserName.Text + "'", con)
                    ra = cb.ExecuteNonQuery()
                    MessageBox.Show("Password Changed Successfully,Now Login into System")
                    MsgBox("Invalid Password or Username")

                End If

            Catch ex As Exception
            End Try
        End If

    End Sub

txtNew is the new password entered by user....
txtRe is the new password re-entered by user....
txtUserName is the username....
txtOld is the old password....

Edited by vishalrane: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.