私は、ユーザーがtxtUsernameとtxtPassに資格情報を入力するログインフォームを持っています。ユーザーと管理者が登録されているテーブルから自動的に選択します。ユーザーがテーブルのUSER-TYPEに応じて資格情報を入力したときに、指定されたフォーム(adminform)と(userform)が表示されます。私はデータベースとブール値にSQL SERVER 2012を使用しました。私はこれでブール値が必要ですか?私はブール値を設定し、どのようにそれを真実にしますか?.NETのユーザータイプに応じて、指定されたフォーム(adminformとuserform)を自動的に表示する方法は?
メトロメッセージボックスを無視します。メトロフレームワークだけです。
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Dim choice As Boolean
con.ConnectionString = My.Settings.ConString
cmd.Connection = con
If txtUser.Text = "" Or txtPass.Text = "" Then
MetroFramework.MetroMessageBox.Show(Me, "Invalid Login", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUser.Clear()
txtPass.Clear()
txtUser.Focus()
ElseIf choice = True Then
Try
con.Open()
cmd.CommandText = "SELECT Name, Password from UserTable where Name = '" & txtUser.Text & "' and Password = '" & txtPass.Text & "' and [User Type]='User'"
dr = cmd.ExecuteReader
If dr.HasRows Then
UserMain.Show()
UserMain.lblName.Text = txtUser.Text
Me.Hide()
End If
Finally
con.Close()
End Try
ElseIf choice = False Then
Try
con.Open()
cmd.CommandText = "SELECT Name, Password from UserTable where Name = '" & txtUser.Text & "' and Password = '" & txtPass.Text & "' and [User Type]='Admin'"
dr = cmd.ExecuteReader
If dr.HasRows Then
AdminMain.Show()
Me.Hide()
End If
Finally
con.Close()
End Try
Else
MetroFramework.MetroMessageBox.Show(Me, "Invalid Login", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
あなたの質問を指定してください – Prisoner
私はすでに私の質問を変更しました –
コードを見れば、2つの脆弱性が明らかです。あなたは[SQLインジェクション](https://en.wikipedia.org/wiki/SQL_injection)につながるクエリーにユーザー入力を連結しており、ユーザーが入力したパスワードとDBを直接比較しているので、それを平文で保存します。少なくとも[PBKDF2](https://en.wikipedia.org/wiki/PBKDF2)を使用してください。 – Alejandro