Imports System.Data.Odbc
Imports MySql.Data.MySqlClient
Imports System.Net.Mail
Public Class Login_Form
Dim errorclose = 1
Private Sub Login_Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Private Sub Login_Form_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Login1_Click(sender, e)
ElseIf e.KeyCode - Keys.Enter Then
Logout1_Click(sender, e)
End If
End Sub
Private Sub Login1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login1.Click
If txtUsername.Text = "" Or txtPassword.Text = "" Then
MsgBox("Please enter UserName and Password")
txtUsername.Focus()
Else
'Connects To the Database
Try
Dim connectionstring As String = "Driver=MySQL ODBC 3.51 Driver;Server=192.168.1.12;port=3306;uid=root;pwd=admin;Database=elcott;"
Dim conn As New OdbcConnection(connectionstring)
conn.Open()
Dim myAdapter As New OdbcDataAdapter
Dim sqlquerry = "Select * From userpass where Username = '" + txtUsername.Text + "' And Password= '" + txtPassword.Text + "'"
Dim myCommand As New OdbcCommand
myCommand.Connection = conn
myCommand.CommandText = sqlquerry
'Starting The Query
myAdapter.SelectCommand = myCommand
Dim mydata As OdbcDataReader
mydata = myCommand.ExecuteReader()
'To check the Username and password and to validate the login a
If mydata.HasRows = 0 Then
If errorclose > 2 Then
MsgBox("The system is closing", MsgBoxStyle.Critical)
Application.Exit()
Else
errorclose += 1
MsgBox("Incorrect password. Please check.", MsgBoxStyle.Critical)
txtUsername.Focus()
End If
Else
Client_chat.txtChatUsername.Text = txtUsername.Text
Client_Main_Window.Show()
Me.Hide()
End If
conn.Close()
Catch myerror As OdbcException
MsgBox
End Try
txtUsername.Text = ""
txtPassword.Text = ""
End Sub
Private Sub Logout1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Logout1.Click
Application.Exit()
End Sub
End Class