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..

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 = ""
            txtNew.Focus()
        ElseIf (txtNew.Text = txtRe.Text) Then

            Try
                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
                    con.Open()
                    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")
                    con.Close()
                    frmLogin.Show()
                    Me.Hide()
                Else
                    MsgBox("Invalid Password or Username")

                End If

            Catch ex As Exception
                MsgBox(ex.Message)
            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....

hello here is a project

all do you want in it by me

are you fa3hed an arab man because i am :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.