私はVB.NETでログインフォームを作成していますが、mysqlにはuserという名前のテーブルがあります。ユーザーがログインできるようになる前に、ユーザー表の管理者列はTRUEに、DELETED列はFALSEにする必要があります。VB.NETログインフォーム認証
+---------------+------------+---------+--------+---------+----------+---------------+---------+
| User_BannerID | FirstName | LastName | Email | Username | Password | Administrator | Deleted |
+---------------+------------+---------+--------+---------+----------+---------------+---------+
| | | | | | | | |
| | | | | | | | |
+---------------+------------+---------+--------+---------+----------+---------------+---------+
ここのコードです:
Imports MySql.Data.MySqlClient
Public Class frmAdlogin
Private Sub cmdCancel_Click(sender As System.Object, e As System.EventArgs) Handles cmdCancel.Click
Application.Exit()
End Sub
Private Sub cmdLogin_Click(sender As System.Object, e As System.EventArgs) Handles cmdLogin.Click
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myConnString As String
Dim UserID As String
myConnString = "server=" & txtServer.Text & ";" _
& "user id=" & txtUsername.Text & ";" _
& "password=" & txtPassword.Text & ";" _
& "database=attendance"
conn.ConnectionString = myConnString
Try
conn.Open()
myCommand.Connection = conn
myCommand.CommandText = "SELECT user_bannerid FROM user WHERE BINARY username = ?Username and administrator = 'TRUE' and deleted = 'FALSE' "
myCommand.Parameters.Add("?Username", txtUsername.Text)
UserID = myCommand.ExecuteScalar
conn.Close()
Dim AdminForm As New frmAdmin
AdminForm.UserID = UserID
AdminForm.connectionString = myConnString
AdminForm.Show()
Me.Hide()
Me.Close()
Catch myerror As MySqlException
MessageBox.Show("Invalid login. Please Enter The Correct Server Address And Your Username Plus The Correct Password ")
conn.Dispose()
End Try
End Sub
Private Sub frmAdlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AcceptButton = cmdLogin
Me.CancelButton = cmdCancel
txtPassword.PasswordChar = "*"
End Sub
End Class
相続人は、ユーザ・テーブルがどのように見えるか
...私は私が知っているすべてを試みたが、すべての非管理者ユーザーはログインすることができますBizAppを編集すると、現在の外観がわかります。Imports MySql.Data.MySqlClient
Public Class frmAdlogin
Private Sub cmdCancel_Click(sender As System.Object, e As System.EventArgs) Handles cmdCancel.Click
Application.Exit()
End Sub
Private Sub cmdLogin_Click(sender As System.Object, e As System.EventArgs) Handles cmdLogin.Click
Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myConnString As String
Dim UserID As String
myConnString = "server=" & txtServer.Text & ";" _
& "user id=" & txtUsername.Text & ";" _
& "password=" & txtPassword.Text & ";" _
& "database=attendance"
conn.ConnectionString = myConnString
conn.Open()
myCommand.Connection = conn
myCommand.CommandText = "SELECT user_bannerid FROM user WHERE BINARY username = ?Username and administrator = 'TRUE' and deleted = 'FALSE' "
myCommand.Parameters.Add("?Username", txtUsername.Text)
Dim dt = New DataTable()
Dim ds = New MySqlDataAdapter(myCommand)
ds.Fill(dt)
If (dt.Rows.Count > 0) Then
conn.Close()
Dim AdminForm As New frmAdmin
AdminForm.UserID = UserID
AdminForm.connectionString = myConnString
AdminForm.Show()
Me.Hide()
Me.Close()
Else
MessageBox.Show("Invalid login. Please Enter The Correct Server Address And Your Username Plus The Correct Password ")
End If
End Sub
Private Sub frmAdlogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AcceptButton = cmdLogin
Me.CancelButton = cmdCancel
txtPassword.PasswordChar = "*"
End Sub
End Class
'ユーザー' テーブルのスキーマ定義は何ですか? –
ああ、その管理者と削除者のENUM( 'TRUE'、 'FALSE') – user1012135