Imports System.Security.Cryptography
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=12345;" & "database=protezione" 'Server data
Try
conn.Open() ' open the connection
Catch myerror As MySqlException
MsgBox("Impossibile connettersi al database: " & myerror.Message.ToString) ' catch the error
End Try
Dim user As String = txtID.Text
Dim pass As String = MD5StringHash(txtPW.Text)
Dim myAdapter As New MySqlDataAdapter
Dim SQLQuery As String = "SELECT * FROM user WHERE Username='" + Replace(user, "", "") + "' AND Password='" + Replace(pass, "", "") & "'" ' Das ist die Abfrage welche Prüft ob der Account existiert.Die txt_benutzer ist die Textbox in der der Benutzername eingeben wird und txt_passwort bekommt das Passwort
Dim myCommand As New MySqlCommand
myCommand.Connection = conn
myCommand.CommandText = SQLQuery
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader() ' start query
If myData.HasRows Then ' if the pw/id is correct
MsgBox("Accesso Consentito.")
conn.Close()
conn.Open()
Else 'Display error
MsgBox("Accesso Negato")
End If
End Sub
End Class