Translating all my code into vb.Net to avoid SQL Injection. With the examples here, I make the new INSERT INTO portion of code and think is working. But I am stuck to get back and verify the data.
Please if can show me a example how to do properly and populate combobox, datagrigview and textboxes.
Aditionally some example to simulate a SQL Injection from vb.Net to testing and learn for beginners developers like me.
My old code to INSERT:
Dim MySQLQuery As String = "INSERT INTO `Agents` (`User_Name`, `User_Pic`) VALUES (AES_ENCRYPT('" & txtUserName.Text & "', '" & MyPass & "'),
AES_ENCRYPT('" & txtUserPic.Text & "', '" & MyPass & "'"
My new parametrized code to INSERT:
MySQLConn.Open()
Dim command As New MySqlCommand()
Dim SQLADD As String = "INSERT INTO `Agents` (`AG_Nom`, `AG_Pic`) VALUES (AES_ENCRYPT('" & "'@UserName'" & "', '" & MyPass & "'), AES_ENCRYPT('" & "'@UserPic'" & "', '" & MyPass & "'))"
command.CommandText = SQLADD
command.Parameters.AddWithValue("@UserName", txtName.Text)
command.Parameters.AddWithValue("@UserPic", txtPicPath.Text)
command.Connection = MySQLConn
command.ExecuteNonQuery()
MySQLConn.Close()
My old code to SELECT:
MySQLQuery = "SELECT AES_DECRYPT(`User_Name`, '" & MyPass & "') AS UName, AES_DECRYPT(`User_Pic`, '" & MyPass & "') AS UPic FROM `Agents`"
MsgBox(MySQLReader.GetString("UName") & vbCrLf & MySQLReader.GetString("UPic")
How build new parametrized SELECT? I try with:
Dim command As New MySqlCommand()
MySQLConn.Open()
Dim SQLID As String = "SELECT AES_DECRYPT(`AG_Nom`, '" & MyPass & "') AS @UserName, AES_DECRYPT(`AG_Pic`, '" & MyPass & "') AS @UserPic FROM `Agents`"
command = New MySqlCommand(SQLID, MySQLConn)
Dim Reader As MySqlDataReader
Reader = command.ExecuteReader()
While Reader.Read
txtDcryName.Text = Reader.GetString("@UserName")
txtDcryPicPath.Text = Reader.GetString("@UserPic")
End While
MySQLConn.Close()
MySQLConn.Dispose()
The last code Not working, error at Reader = command.ExecuteReader()
TIA