Imports System Imports System.Data Imports System.Data.SqlClient Imports System.IO Imports System.IO.Ports Public Class failverification 'Private cnstr As String Private Sub btn_ok_Click(sender As System.Object, e As System.EventArgs) Handles btn_ok.Click Dim cnstr = mainForm.cnstr Dim conn As New SqlConnection(cnstr) Dim myQuery As String myQuery = "SELECT * FROM users WHERE password = '" & txtPassword.Text & "'" Try conn.Open() Dim mycommand As SqlCommand mycommand = New SqlCommand(myQuery, conn) Dim reader As SqlDataReader = mycommand.ExecuteReader() 'auth.Text = reader("authentication") If (reader.HasRows) Then reader.Read() If reader("authentication").ToString = "Administrator" Or reader("authentication").ToString = "Super Administrator" Then mountingForm.Enabled = True comport() SerialPort1.Open() SerialPort1.Write("A") SerialPort1.Close() Me.Close() Else MessageBox.Show("You are not an authorized admin!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("You are not an authorized admin!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Catch ex As Exception Finally conn.Close() conn.Dispose() End Try conn.Close() mountingForm.Enabled = True End Sub Private Sub comport() SerialPort1.Close() SerialPort1.PortName = ComportLabel.Text SerialPort1.BaudRate = 9600 SerialPort1.DataBits = 8 SerialPort1.Parity = Parity.None SerialPort1.StopBits = StopBits.One SerialPort1.Handshake = Handshake.None SerialPort1.Encoding = System.Text.Encoding.Default End Sub Private Sub txtPassword_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyUp If e.KeyCode = Keys.Enter Then Dim cnstr = mainForm.cnstr Dim conn As New SqlConnection(cnstr) Dim myQuery As String myQuery = "SELECT * FROM users WHERE password = '" & txtPassword.Text & "'" Try conn.Open() Dim mycommand As SqlCommand mycommand = New SqlCommand(myQuery, conn) Dim reader As SqlDataReader = mycommand.ExecuteReader() 'auth.Text = reader("authentication") If (reader.HasRows) Then reader.Read() If reader("authentication").ToString = "Administrator" Or reader("authentication").ToString = "Super Administrator" Then mountingForm.Enabled = True comport() SerialPort1.Open() SerialPort1.Write("A") SerialPort1.Close() Me.Close() Else MessageBox.Show("You are not an authorized admin!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else MessageBox.Show("You are not an authorized admin!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Catch ex As Exception Finally conn.Close() conn.Dispose() End Try conn.Close() mountingForm.Enabled = True End If End Sub Private Sub failverification_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load ComportLabel.Text = sequential.ComTextBox.Text End Sub End Class