Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Imports System.IO
- Public Class frmlogin
- Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
- End
- End Sub
- Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
- On Error GoTo err
- Dim conn As New MySqlConnection
- Dim areader As MySqlDataReader
- Dim cmd As New MySqlCommand
- Dim loginat As Integer = 0
- conn.ConnectionString = "Server = localhost; Database = data; User ID = root; Password = "
- cmd.Connection = conn
- conn.Open()
- cmd.CommandText = "select * from admin where username ='" & txtuser.Text & "'"
- cmd.Connection = conn
- areader = cmd.ExecuteReader()
- Dim validlogin As Boolean
- validlogin = False
- If areader.HasRows = True Then
- areader.Read()
- If areader.Item("password") = txtpass.Text Then
- validlogin = True
- Dim fn, position, user_type As String
- Dim image As String
- fn = areader.Item("FirstName")
- position = areader.Item("position")
- user_type = areader.Item("type")
- If txtuser.Text = "" And txtpass.Text = "" Then
- MsgBox("Please fill in all boxes")
- ElseIf user_type = "Main Admin" Then
- MsgBox("Welcome " & fn & " you login as Main Administrator ", MsgBoxStyle.Information, "Access Granted")
- loginat = 0
- frmadmain.Show()
- Me.Hide()
- frmadmain.lblname.Visible = True
- frmadmain.lblname.Text = fn
- frmadmain.txtUser.Text = user_type
- txtuser.Text = ""
- txtpass.Text = ""
- Else
- MsgBox("Welcome " & fn & " you login as " & position & " ", MsgBoxStyle.Information, "Access Granted")
- loginat = 0
- frmmain.Show()
- Me.Hide()
- frmadmain.lblname.Visible = True
- frmadmain.lblname.Text = fn
- frmadmain.txtUser.Text = user_type
- txtuser.Text = ""
- txtpass.Text = ""
- End If
- Else
- txtuser.Text = ""
- txtpass.Text = ""
- txtuser.Focus()
- txtpass.Focus()
- MsgBox("Password not match", MsgBoxStyle.Exclamation, "Access Denied")
- loginat += 1
- End If
- Else
- txtuser.Text = ""
- txtpass.Text = ""
- txtuser.Focus()
- txtpass.Focus()
- MsgBox("Incorrect username", MsgBoxStyle.Exclamation, "Access Denied")
- loginat += 1
- End If
- lbllog.Text = loginat
- If loginat = 2 Then
- MsgBox("Last change to login, or the system will close!", MsgBoxStyle.Exclamation, "Caution")
- ElseIf loginat = 3 Then
- MsgBox("Sorry the system will now close!", MsgBoxStyle.Exclamation, "Caution")
- Me.Close()
- End If
- If validlogin = True Then
- Dim alreadylogin = True
- Dim userlogin = areader.Item("username")
- txtuser.Text = ""
- txtpass.Text = ""
- areader.Close()
- ' you can add another code or call function in this section
- ''Me.Dispose()
- Else
- areader.Close()
- txtpass.Text = ""
- MsgBox(Err, MsgBoxStyle.Information)
- End If
- Exit Sub
- err:
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement