Dim db = HySql.DataBaseFactory.CreateDatabase("T4") '
Dim username As String = e.Form.Controls("usernameT").Value
If username = "" Then
Messagebox.show("请选择用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
Dim Sq-l = "Selec-t * From 用户表 Where Name = '" & username & "'"
Dim dt As system.data.DataTable = db.ExecuteDataSet(Sq-l).Tables(0)
'Msgbox(dt.Rows.Count)
If dt.Rows.Count = 0 Then
Messagebox.show("此用户不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
If e.Form.Controls("password").text = dr("password").tostring Then '
_姓名 = username
_UFFFGroup = dr("Group").tostring'
Else
Messagebox.show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
上面是用户登录,网上查一下,说这样会SQL注入,如何有效防止SQL注入?
[此贴子已经被作者于2024/8/21 15:49:24编辑过]
如果还需要使用HySql,那么请去看这个组件的帮助。没有办法和网上的东西整合到一起
Dim db = HySq-l.DataBaseFactory.CreateDatabase("T4") '
Dim username As String = e.Form.Controls("usernameT").Value
Dim password As String = e.Form.Controls("passwordT").Value
If username = "" Then
Messagebox.show("请选择用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
Dim Sq-l = "Selec-t * From 用户表 Where 姓名 = ? and 密码 = ?"
Dim dt As Integer = db.ExecuteNonQuery(Sql, HySql.ParameterPair.GetPair("姓名", "username"), HySql.ParameterPair.GetPair("密码", "password"))
'If dt.Rows.Count = 0 Then
' Messagebox.show("此用户不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
' Return
'End If
If dt = 0 Then
Messagebox.show("此用户不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
Return
End If
Dim dr As system.data.DataRow
dr = dt.Rows(0) '
If e.Form.Controls("password").text = dr("password").tostring Then '
_姓名 = username
_UFFGroup = dr("Group").tostring'
Else
Messagebox.show("密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
问题1:红代码,报错Rows不是Integer,怎么改?参数法是蓝代码那样?
问题2:这个登录很重要,帮处理,让它严谨,安全,防止注入?
Dim dt As System.Data.DataTable = db.ExecuteDataSet(Sql, HySql.ParameterPair.GetPair("姓名", username), HySql.ParameterPair.GetPair("密码", password)).Tables(0)