I do have an annoying problem here, I am not able troubleshoot this issue. My problem is that I cannot confirm my login, somewhere's a logical error because my try-catch block is not 'catching' anything, I even used breakpoints between DataBase Opening and DB.Close to see if there's any issue. Here are some screens :
So if I enter the user Gigel and his password 123 (it's encrypted) I get my false execution from my IF , 'Something's wrong out there'
Error..., anyone ?
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.Security.Cryptography
Public Class Form1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim MySQLConnection As New MySqlConnection("Server = localhost;Database = users; Uid=root; Pwd = password ")
Dim HashedPass As String = ""
'Converts the Password into bytes, computes the hash of those bytes, and then converts them into a Base64 string
Using MD5hash As MD5 = MD5.Create()
System.Convert.ToBase64String(MD5hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(TextBox2.Text)))
End Using
'Counter
Dim SqlQuery As String = "SELECT COUNT(*) From users1 WHERE username = @Username AND password = @Password; "
MySQLConnection.Open()
Dim Command As New MySqlCommand(SqlQuery, MySQLConnection)
'Sanitising parameters
Command.Parameters.Add(New MySqlParameter("@Username", TextBox1.Text))
Command.Parameters.Add(New MySqlParameter("@Password", HashedPass))
'checker
If Command.ExecuteScalar() = 1 Then
MsgBox("Thanks for logging in")
Me.Hide()
Else
MsgBox("Something's wrong down there")
End If
MySQLConnection.Close()
End Sub
End Class