This code is supposed to check if the username and reset keyword match and the enable 2 textboxes and when the users inputs text and click the button it send a SQLite command and updates the password value on the database, but for some reason when the button is clicked it does nothing and even whit the try catch i doesn't show any errors

Here is the code:

Imports System.Data.SQLite
Imports System.Security.Cryptography
Imports System.Text

Public Class resetar_pass
    Dim hash_reset As String
    Dim encriptacao_SHA512 As SHA512 = SHA512.Create()

    Private Sub resetar_pass_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Public Sub encriptar_reset()
        Dim valor_do_hash_reset As Byte() = encriptacao_SHA512.ComputeHash(Encoding.UTF8.GetBytes(TextBox1.Text))
        hash_reset = Convert.ToBase64String(valor_do_hash_reset)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using connection As New SQLiteConnection(connectionString)
            connection.Open()

            Try
                    encriptar_reset()

                    If TextBox2.Text = TextBox3.Text Then
                    Dim resetar As String = $"UPDATE login SET password = '{TextBox3.Text}' WHERE       username = '{UsernameTextBox.Text}' AND reset = '{hash_reset}';"
                    Dim reset As New SQLiteCommand(resetar, connection)
                    reset.ExecuteNonQuery()


                Else
                        MessageBox.Show("As passwords não coicidem!")
                    End If

                Catch ex As SQLiteException
                    MessageBox.Show($"Erro ao atualizar password: {ex.Message} (Error code: {ex.ErrorCode})")


                End Try

            End Using

    End Sub

    Private Sub verificar(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
        Using connection As New SQLiteConnection(connectionString)
            connection.Open()
            encriptar_reset()
            Dim reset_pass As String = $"SELECT * FROM login WHERE username = '{UsernameTextBox.Text}' AND reset = '{hash_reset}';"
            Dim login_command As New SQLiteCommand(reset_pass, connection)

            Dim reader As SQLiteDataReader = login_command.ExecuteReader()

            If reader.HasRows Then
                TextBox2.Visible = True
                TextBox3.Visible = True
                connection.Close()
            Else
                MessageBox.Show("O nome de utilizador ou a password está errada!")
            End If
        End Using
    End Sub
End Class

I tried closing the connection here

Private Sub verificar(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick
        Using connection As New SQLiteConnection(connectionString)
            connection.Open()
            encriptar_reset()
            Dim reset_pass As String = $"SELECT * FROM login WHERE username = '{UsernameTextBox.Text}' AND reset = '{hash_reset}';"
            Dim login_command As New SQLiteCommand(reset_pass, connection)

            Dim reader As SQLiteDataReader = login_command.ExecuteReader()

            If reader.HasRows Then
                TextBox2.Visible = True
                TextBox3.Visible = True
                --> connection.Close()
            Else
                MessageBox.Show("O nome de utilizador ou a password está errada!")
            End If
        End Using
    End Sub

and used a try catch to check for errors that SQLite might send but it doesn't show anything

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Using connection As New SQLiteConnection(connectionString)
            connection.Open()

            Try
                    encriptar_reset()

                    If TextBox2.Text = TextBox3.Text Then
                    Dim resetar As String = $"UPDATE login SET password = '{TextBox3.Text}' WHERE       username = '{UsernameTextBox.Text}' AND reset = '{hash_reset}';"
                    Dim reset As New SQLiteCommand(resetar, connection)
                    reset.ExecuteNonQuery()


                Else
                        MessageBox.Show("As passwords não coicidem!")
                    End If

                Catch ex As SQLiteException
                    MessageBox.Show($"Erro ao atualizar password: {ex.Message} (Error code: {ex.ErrorCode})")


                End Try

            End Using

    End Sub
0

There are 0 best solutions below