【发布时间】:2020-06-19 12:25:06
【问题描述】:
我正在使用一个 XAMPP 本地托管的 MySQL 服务器和我的登录数据库。我正在尝试将数据库中的条目与 vb 程序中文本框的输入进行比较。但是,单击按钮后,程序会冻结。
Imports MySql.Data.MySqlClient
Public Class Login
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Parts.User' table. You can move, or remove it, as needed.
'Me.UserTableAdapter.Fill(Me.Parts.User)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Oops ¯\_(ツ)_/¯ " + Err.Description(), MsgBoxStyle.OkOnly, "Enter Value")
Else
Try
Dim connectionString = "server=localhost; userid=root; password=; database=partstest1; CharSet=utf8;"
Dim connDB = New MySqlConnection(connectionString)
Try
connDB.Open()
Dim objCmd = New MySqlCommand
objCmd.Connection = connDB
objCmd.CommandText = "SELECT ID, Username, Password FROM `user` WHERE `Username` = '" + TextBox1.Text + "' and `Password` = '" + TextBox2.Text + "';"
objCmd.CommandType = CommandType.Text
Dim objAdpt = New MySqlDataAdapter
Dim objDS = New DataSet
objAdpt.SelectCommand = objCmd
objAdpt.Fill(objDS)
Console.WriteLine(objDS)
If TextBox1.Text = "admin" Then
'If Access_Level = 0 Then
Me.Hide()
AdminMainMenu.Show()
Else
Me.Hide()
MainMenu.Show()
End If
Catch
MsgBox("Oops " + Err.Description(), MsgBoxStyle.OkOnly, "Failed to Open")
MsgBox("Incorrect login details", MsgBoxStyle.OkOnly)
End Try
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End If
TextBox1.Clear()
TextBox2.Clear()
End Sub
End Class
我尝试将 TextBox.Text 设置为一个不同的变量,但它没有产生任何影响。我的命令是否太复杂或者我的格式是否错误?我对 SQL 很陌生,因此我们将不胜感激。
【问题讨论】:
-
从不将密码作为文本存储在您的数据库中,只有散列的密码
-
哦,它们是散列的,我正在尝试一个未散列的开始,因为我要搞砸的事情更少。我正在使用 SHA256 作为哈希
-
我也将其简化为简单的单词,看看它是否会对计算时间产生影响
-
另外,不要在你的 UI 线程上做这个数据库的东西。使用
Async / Await卸载它。这将使您的程序不会冻结,但不一定有助于超时。 -
对不起,我不太明白,也感谢您编辑我的问题:)