Securing records when it comes to editing - vb.net-2010

Assuming that there's value in all of the textfields and comboboxes. I want that when i click the edit button, there will be a pop up window that will require the users password before enabling the text fields.. is it possible? if yes? what's the code/syntax. Thanks in advance!

Yes, it possible, here i used Mike as a username and Mike124 as a password, here is the code to do that :
'Here is the click event when the user clicks on the edit button
Private Sub EditBUT_Click(sender As Object, e As EventArgs) Handles EditBUT.Click
RecheckUsername: Dim UserNameInput As String = InputBox("Please enter your username :")
If UserNameInput = "Mike" And UserNameInput <> "" Then
ReheckPassword: Dim PasswordInput As String = InputBox("Please enter your password :")
If PasswordInput = "Mike124" And PasswordInput <> "" Then
'Enable the all the fields here because the username and the password are correct
Else
'The password is wrong
MsgBox("Please check your password and try again")
GoTo ReheckPassword
End If
Else
'The username is wrong
MsgBox("Please check your username and try again")
GoTo RecheckUsername
End If
End Sub
If you want a way to store the username and the password, you can use My.Settings.Username and My.Settings.Password, but first you need to define them in the properties of your solution, just go to the Project tab in the Toolbar and click on Properties, then go to the Settings tab and set the Username and the Password variables.
Hope that helped you with what you need :)

Private Sub ACCOUNT_RECHECK()
Dim UserNameInput As String = InputBox("Please Enter your Username:")
Dim PasswordInput As String = InputBox("Please Enter your Password:")
Try
dbconnect.Open()
qInsert = "Select * from tblAdmin where Admin_UName='" & UserNameInput & "' and Admin_Password='" & PasswordInput & "'"
dbcommand = New OleDbCommand(qInsert, dbconnect)
dbcommand.ExecuteNonQuery()
Dim dr = dbcommand.ExecuteReader
If dr.Read = True Then
AccountType1 = dr("Admin_Type")
AccessGranted1 = True
dbconnect.Close()
Else
AccessGranted1 = False
End If
dbconnect.Close()
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
ACCOUNT_RECHECK()
If AccountType1 = False Then
MsgBox("INVALID! YOU'RE NOT ALLOWED TO MODIFY THIS DATA!", MsgBoxStyle.Exclamation)
End If
If AccessGranted1 = True Then
MsgBox("ACCESS GRANTED!", MsgBoxStyle.Information)
If AccountType1 = 1 Then
TAGA_ENABLE()
TAGA_ENABLEB()
ElseIf AccountType1 = 2 Then
MsgBox("Sorry, your access role is only for viewing! Kindly ask the Admin to change your role to modify this data", MsgBoxStyle.Information)
End If
End If
End Sub

Related

Login form in VB.Net using Access database not working

I'm pretty sure this code used to allow me to login using the SQL statement below, but now it doesn't and just clears the text boxes.
There is also an error message that I would like displayed when the username and password do not match that in the database. This is, like the other one, a label that the visibility would need changing. I had this code:
Try
UserType = GetUserType(txtUsername.Text.Trim, txtPass.Text.Trim)
Catch ex As Exception
lblErrorMatch.Visible = True
End Try
However, this just clears the text boxes when the details do not match.
Imports System.Data.OleDb
Public Class frmLogin
Private DBCmd As New OleDbCommand
Private ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;" &
"Data Source=|DataDirectory|\NewHotel.mdb;"
Private Sub btnLogIn_Click(sender As Object, e As EventArgs) Handles btnLogIn.Click
Dim UserType As Object
'Distinguishing beetween different users
If UserType Is Nothing Then
lblErrorEmpty.Visible = True
ElseIf UserType.ToString = "MANAGER" Then
frmHomeManager.Show()
ElseIf UserType.ToString = "RECEPTIONIST" Then
frmHomeReceptionist.Show()
End If
'Username and password not matching error message
'Empty textboxes error message
If txtUsername.Text = "" OrElse txtPass.Text = "" Then lblErrorEmpty.Visible = True : Exit Sub
txtUsername.Clear()
txtPass.Clear()
chkShowPass.Checked = False
End Sub
Private Function GetUserType(Username As String, Pass As String) As Object
Dim UserType As Object
'Pull username and password from the database to check against the entered login details
Using DBCon As New OleDb.OleDbConnection(ConStr),
DBCmd As New OleDbCommand("SELECT UserType FROM tblEmployeeLogin WHERE [Username] = #Username AND [Pass] = #Pass", DBCon)
DBCmd.Parameters.Add("#Username", OleDbType.VarChar).Value = Username
DBCmd.Parameters.Add("#Pass", OleDbType.VarChar).Value = Pass
DBCon.Open()
UserType = DBCmd.ExecuteScalar.ToString
End Using
Return UserType
End Function
Private Sub chkShowPass_CheckedChanged(sender As Object, e As EventArgs) Handles chkShowPass.CheckedChanged
'Show password when checkbox is checked
If chkShowPass.Checked = True Then
txtPass.PasswordChar = Nothing
ElseIf chkShowPass.Checked = False Then
txtPass.PasswordChar = "*"
End If
End Sub
Private Sub txtUsername_TextChanged(sender As Object, e As EventArgs) Handles txtUsername.TextChanged, txtPass.TextChanged
'Make error message disappear after text is enetered into either of the text boxes
lblErrorEmpty.Visible = False
lblErrorMatch.Visible = False
End Sub
Private Sub lnkClear_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lnkClear.LinkClicked
txtUsername.Clear()
txtPass.Clear()
chkShowPass.Checked = False
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
'Close the form down which stops the application
Me.Close()
End Sub
End Class
Thank you for your time :)
I recently made a login like what you're trying to do. Hopefully you understand this code and it helps:
Dim CMD As OleDbCommand = New OleDbCommand("SELECT * FROM Staff WHERE Login = '" & ID & "'", Con)
Dim user As String
Try
Con.Open()
Dim sdr As OleDbDataReader = CMD.ExecuteReader()
If (sdr.Read() = True) Then
user = sdr("Login")
MessageBox.Show("Login Successful!")
ActiveUser.IsLoggedIn = True
Else
MessageBox.Show("Invalid username or password!")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
Con.Close()
End Try

Not fetching username and password from textfile

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim FILE_NAME As String = Cashierpath
System.IO.File.Exists(FILE_NAME) ' current
Dim objReader As StreamReader
Dim user As String = TextBox1.Text
Dim password As String = TextBox2.Text
Dim check As String
'Global Variable
'Dim DirPath7 As String = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Scrap Data\Cashier Info\Cashiers\")
For Each filename As String In IO.Directory.EnumerateFiles(DirPath7, "*.txt")
Dim fName As String = IO.Path.GetFileName(filename)
If user = fName & ".txt" Then
objReader = New StreamReader(fName)
check = objReader.ReadToEnd()
If password = check Then
MessageBox.Show("Welcome " & user & "!")
Close()
My.Forms.Home.Show()
Else
MessageBox.Show("Username or Password is incorrect")
End If
End If
Next
End Sub
When the user enters their "username" and "password" into the textbox's, and clicks on this button, i want this button to check if there is a textfile with the name of the username entered, and if theres a file with that username it must then read it and check if the password matches the string inside the file. if it doesnt match it, it must then display a messagebox saying that "Username or password is incorrect", but nothing happens when i click on this button. No error message appears either.
Can someone take a look at my code and tell me what im doing wrong?
What you have there is an awful way to handle user credentials!
Read this for more information: Salted Password Hashing - Doing it Right
Regardless, you're way over-coding it.
Elsewhere in your app (correct use of Combine):
' Global Variable
Friend Shared DirPath7 As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Scrap Data", "Cashier Info", "Cashiers")
Button Handler:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim User As String = TextBox1.Text.Trim
Dim Pass As String = TextBox2.Text.Trim
' Assemble the full expected file path, even if it might be malformed.
' The first case check protects against malformed path.
Dim FilePath As String = IO.Path.Combine(DirPath7, String.Format("{0}.txt", User))
Select Case True
Case User.Length = 0
MsgBox("Username is empty", vbExclamation, "Error")
Case Pass.Length = 0
MsgBox("Password is empty", vbExclamation, "Error")
Case Not IO.File.Exists(FilePath)
MsgBox("No file for User", vbExclamation, "Error")
Case Not IO.File.ReadAllText(FilePath) = Pass
MsgBox("Wrong Password", vbExclamation, "Error")
Case Else
MsgBox(String.Format("Welcome {0}!", User), vbOKOnly, "Success")
My.Forms.Home.Show()
End Select
End Sub
Dim objReader As StreamReader
Dim user As String = TextBox1.Text
Dim password As String = TextBox2.Text
Dim check As String
Dim fname = Path.Combine(DirPath7, String.Format("{0}.txt", user))
If File.Exists(fname) Then
Using objreader As New StreamReader(fname)
'objReader = StreamReader(fname)
check = objreader.ReadToEnd()
password = check
MessageBox.Show("Welcome " & user & "!")
Close()
My.Forms.Home.Show()
End Using
Else : MessageBox.Show("file not found, no user exists")
End If
removed the extra ".txt"
Added "Do Using" . . ."End Using"

Visual Basic 2010 Express: Check if my.settings.username has a value

VISUAL BASIC: You know how you can make your own settings in your program setting/properties, well I made a register system for a software. You register by entering a password and username then pressing 'Register' to save the username and password to My.Settings.Username and My.Settings.Password using My.Settings.Save().
The code: My.Settings.Username = TextBox1.Text
My.Settings.Password = TextBox2.Text
My.Settings.Save()
This all works perfectly but how can I prevent the user from changing it again.
This is my code so far:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim res As MsgBoxResult
If Not My.Settings.Username = String.Empty And
My.Settings.Password = String.Empty Then
MsgBox("You have registered a WCUE account, please use 'CHANGE PASSWORD' in 'Settings' to do so.", MsgBoxStyle.Exclamation, "Not possible.")
ElseIf TextBox1.Text = String.Empty Or
TextBox2.Text = String.Empty Then
MsgBox("Don't press the register button if the text boxes are empty!", MsgBoxStyle.Critical, "Fill all required fields please.")
Else
If TextBox1.Text = My.Settings.Username And
TextBox2.Text = My.Settings.Password Then
MsgBox("If you are trying to log in then press the 'Log-in' text below the register button!", MsgBoxStyle.Exclamation, "You have already registered!")
Else
res = MsgBox("Register a WCUE account?", MsgBoxStyle.YesNo, "Create")
If res = MsgBoxResult.Yes Then
My.Settings.Username = TextBox1.Text
My.Settings.Password = TextBox2.Text
My.Settings.Save()
MsgBox("You can now login to WCUE and set the time limit on this user!", MsgBoxStyle.Information, "YEAH - Register successful!")
ElseIf res = MsgBoxResult.No Then
MsgBox("You should register as quick as possible before someone unauthorized sets a password!!", MsgBoxStyle.Exclamation, "Suit yourself.")
End If
End If
Exit Sub
End If
End Sub
The FIRST if statement is what I am having trouble with, I tried to check if My.Settings.Username and My.Setting.Password contains a value (string) which should be the username and password, if it does not then you can register but if it does contain a value then it tells you that someone has already registered. Nothing happens?
I hope this is clear enough, please help!
I ~think~ this is what you're trying to do...
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If My.Settings.Username <> String.Empty AndAlso My.Settings.Password <> String.Empty Then
MsgBox("You have registered a WCUE account, please use 'CHANGE PASSWORD' in 'Settings' to do so.", MsgBoxStyle.Exclamation, "Not possible.")
Else
If TextBox1.Text = String.Empty OrElse TextBox2.Text = String.Empty Then
MsgBox("Don't press the register button if the text boxes are empty!", MsgBoxStyle.Critical, "Fill all required fields please.")
Else
Dim res As MsgBoxResult
res = MsgBox("Register a WCUE account?", MsgBoxStyle.YesNo, "Create")
If res = MsgBoxResult.Yes Then
My.Settings.Username = TextBox1.Text
My.Settings.Password = TextBox2.Text
My.Settings.Save()
MsgBox("You can now login to WCUE and set the time limit on this user!", MsgBoxStyle.Information, "YEAH - Register successful!")
ElseIf res = MsgBoxResult.No Then
MsgBox("You should register as quick as possible before someone unauthorized sets a password!!", MsgBoxStyle.Exclamation, "Suit yourself.")
End If
End If
End If
End Sub

VB Strip Menu MDI parent disabling from MDI Child issue

i need some help in VB. I just started learning vb today.
so I have an MDIParent form, which contain login, logout(disabled) and other disabled strip menu.
so when i click the login, the login form is appeared as MDI child window.
the question is, when i successfully logged in i want to make the login Strip Menu disabled, enabling the logout Strip Menu and the other strip menu. I have tried to make it. Here's my code now :
Imports MySql.Data.MySqlClient
Public Class LoginForm
Dim mdiP As New MDIParent
Dim myconn As New MySqlConnection("Server=localhost; User Id=root; Password=; Database=apotek_db")
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
If UsernameTextBox.Text = "" Or PasswordTextBox.Text = "" Then
MsgBox("Please insert username and password")
End If
Dim username As String = UsernameTextBox.Text
Dim password As String = PasswordTextBox.Text
Dim myAdapter As New MySqlDataAdapter("select * from admin where USERNAME = '" & username & "' and PASSWORD = '" & password & "'", myconn)
Dim myDataTable As New DataTable
myAdapter.Fill(myDataTable)
If myDataTable.Rows.Count < 1 Then
PasswordTextBox.Clear()
UsernameTextBox.Clear()
MsgBox("Invalid username or password")
Else
MsgBox(username & " Successfully logged in")
mdiP.logOutMenu.Enabled = True
mdiP.logInMenu.Enabled = False
mdiP.TransaksiPenjualanToolStripMenuItem.Enabled = True
mdiP.DataObatToolStripMenuItem.Enabled = True
Me.Close()
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
mdiP.Show()
Me.Close()
End Sub
End Class
But the code above doesn't disabling or enabling anything in the MDI parent. it just showing message box than i successfully logged in, and close the login form. thats it.
so anyone have any solution for me?
Thanks in advance,
Rezz.

How to validate a username password and usertype login in Vb.net?

How to validate a username and password to login and then also check the usertype, based on which different events can be triggered?
for example admin has certain privileges and normal user has different privileges.
Public Class Login
Dim con As New OleDb.OleDbConnection
'new connection to database
Dim dbprovider As String
'to gets the probider name
Dim dbsource As String
'to gets the database provider name
Dim ds As New DataSet
'dataset to table
Dim da As OleDb.OleDbDataAdapter
'databaseAdapter to dataset and database
Dim sql As String
'sql command
Dim usrname1, pswd1, usrtype As String
Dim maxrows, incdec As Integer
'string variables
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'validation of username and password
If txtb_uname.Text = usrname1 And txtb_pwd.Text = pswd1 Then
If usrtype = "admin" Then
Score.Show()
Score.btn_delete.Enabled = False
Score.btn_update.Enabled = False
Score.Button2.Enabled = False
Score.Button1.Enabled = False
'username and password correct go to the netx page
ElseIf txtb_uname.Text = usrname1 And txtb_pwd.Text = "" Then
MsgBox("Enter Password")
'blank password control
ElseIf txtb_uname.Text = "" And txtb_pwd.Text = pswd1 Then
MsgBox("Enter Username")
'blank username control
ElseIf txtb_uname.Text = usrname1 And txtb_pwd.Text <> pswd1 Then
MsgBox("Invalid Password")
'incorrect pasword
ElseIf txtb_uname.Text <> usrname1 And txtb_pwd.Text = pswd1 Then
MsgBox("Invalid Username")
'incorrect username
ElseIf txtb_uname.Text = "" And txtb_pwd.Text = "" Then
MsgBox("enter Username")
'blank username and password
Else
MsgBox("invalid usertype")
End If
Else
MsgBox("Invalid Username & or Password")
'incorrect username and password
End If
End Sub
Lets assume that your database has a table containing the username, password and a boolean which is called something like isAdmin and can be set on true or false, depending on the users rights.
Now you have to use your DB connection to validate the username and the password. Here is a little example:
Public Shared Function Login(ByVal Name As String, ByVal Password As String) As Boolean
Shared OleDbConString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & My.Settings.Netzwerkpfad & ";" 'you'll have to enter your own provider etc. I just copied it from another project
Shared con As OleDbConnection = New OleDbConnection(OleDbConString) 'establish the connection
Shared cmd As New OleDbCommand 'your sql statement
Shared reader As OleDbDataReader 'Saving the data you'll get
Dim Checkpassword String = "" 'The string where you'll put the password you get from the databse
Dim isAdmin as boolean = False
Try
cmd.Connection = con
cmd.CommandText = "SELECT Password, isAdmin FROM tbl_User WHERE Name = '" & Name & "';" 'tbl_User is just the table name, this may be different in your DB
con.Open() 'opens the database connection
reader = cmd.ExecuteReader 'executes your command
Do While reader.Read
Checkpassword = reader("Password") 'reader("Password") returns the column "Password" in your databse
isAdmin = reader("isAdmin") 'Returns true or false depending on the users rights
Loop
If Password.Equals(Checkpassword ) Then 'Checks if the entered password is correct
If isAdmin = True Then 'Check if Admin and based on the outcome call the functions or save the outcome into global variables
Else
End If
Else
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error while trying to log in", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
Finally
con.Close()
End Try
End Function
Public Class frmAdminLoginpage
Dim ErrorCount As Integer
Private Sub frmAdminLoginpage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ErrorCount = 0
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
MessageBox.Show("Are you sure you want to Exit?", "Exit", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
Me.Close()
End Sub
Private Sub lblCreateAccount_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblCreateAccount.LinkClicked
frmRegister.Show()
Me.Hide()
End Sub
Private Sub lblForgotPassword_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lblForgotPassword.LinkClicked
frmForgotPassword.Show()
Me.Hide()
End Sub
Sub ClearControls()
txtLoginID.Text = ""
txtLoginPassword.Text = ""
txtLoginID.Focus()
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear text
ClearControls()
End Sub
Protected Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
Dim strConnectionString As String
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim strSQL As String
' Check if ID or password is empty
If txtLoginPassword.Text = "" Or txtLoginID.Text = "" Then
MessageBox.Show("Please Enter your ID and Password.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' Both fields was supply
' Check if user exist in database
' Connect to Database
strConnectionString = "Data Source=LENOVO-PC; Initial Catalog=VB; Integrated Security=True"
Try
'Database records will verify the Staff ID, password and position from the Staff Database
strSQL = "Select * FROM Staff WHERE StaffID='" & txtLoginID.Text & "'And Password = '" & txtLoginPassword.Text & "'And Position='Administrator'"
'strSQL = "Select * FROM Staff WHERE Position='Administrator'"
sqlCnn = New SqlConnection(strConnectionString)
'Open Database Connection
sqlCnn.Open()
sqlCmd = New SqlCommand(strSQL, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader
If sqlReader.Read() Then
frmSales_Admin.Show()
Me.Hide()
Else
' If user enter wrong ID and password
' Throw an error message
MessageBox.Show("Incorrect User ID and Password..", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ErrorCount = ErrorCount + 1
'Clear all fields
txtLoginID.Text = ""
txtLoginPassword.Text = ""
'Focus on login ID field
txtLoginID.Focus()
'If login was not successful at the first time, the user will only have two more Login attempts left
If (ErrorCount = 1) Then
lblNotify.Text() = "You have 2 login attempts left"
'If login was not successful for the second time, the user will only have one more Login attempts left
ElseIf (ErrorCount = 2) Then
lblNotify.Text() = "You have 1 login attempt left"
'If login was not successful for the third time, the user will not have anymore attempts left
ElseIf (ErrorCount = 3) Then
MessageBox.Show(" You have exceeded the maximum login attempts. System is now exiting. ", " Error! ", MessageBoxButtons.OK, MessageBoxIcon.Error)
'The system will then exit after the message box is closed
Application.Exit()
End If
End If
Catch ex As Exception
MessageBox.Show("Failed to connect to Database.", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
Private Sub chkShowPassword_CheckedChanged(sender As Object, e As EventArgs) Handles chkShowPassword.CheckedChanged
'To Make Password Visible
If chkShowPassword.Checked Then
txtLoginPassword.PasswordChar = ""
ElseIf chkShowPassword.Checked = False Then 'To make password not visible
txtLoginPassword.PasswordChar = "*"
End If
End Sub
Private Sub txtLoginID_DoubleClick(sender As Object, e As EventArgs) Handles txtLoginID.DoubleClick
txtLoginID.Clear()
txtLoginID.Focus()
End Sub
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
'To go back to the main page of the app
frmSmartBookStore.Show()
Me.Hide()
End Sub
Private Sub txtLoginPassword_KeyDown(sender As Object, e As KeyEventArgs) Handles txtLoginPassword.KeyDown
Dim strConnectionString As String
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim strSQL As String
'If user press enter key on password textbox
If e.KeyCode = Keys.Enter Then
If txtLoginPassword.Text = "" Or txtLoginID.Text = "" Then
MessageBox.Show("Please Enter your ID and Password.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' Both fields was supply
' Check if user exist in database
' Connect to Database
strConnectionString = "Data Source=LENOVO-PC; Initial Catalog=VB; Integrated Security=True"
Try
strSQL = "Select * FROM Staff WHERE StaffID='" & txtLoginID.Text & "'And Password = '" & txtLoginPassword.Text & "'And Position='Administrator'"
'strSQL = "Select * FROM Staff WHERE Position='Administrator'"
sqlCnn = New SqlConnection(strConnectionString)
'Open Database Connection
sqlCnn.Open()
sqlCmd = New SqlCommand(strSQL, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader
If sqlReader.Read() Then
frmSales_Admin.Show()
Me.Hide()
Else
' If user enter wrong username and password combination
' Throw an error message
MessageBox.Show("Incorrect User ID or Password..", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
ErrorCount = ErrorCount + 1
'Clear all fields
txtLoginID.Text = ""
txtLoginPassword.Text = ""
'Focus on login ID field
txtLoginID.Focus()
'If login was not successful at the first time, the user will only have two more Login attempts left
If (ErrorCount = 1) Then
lblNotify.Text() = "You have 2 login attempts left"
'If login was not successful for the second time, the user will only have one more Login attempts left
ElseIf (ErrorCount = 2) Then
lblNotify.Text() = "You have 1 login attempt left"
'If login was not successful for the third time, the user will not have anymore attempts left
ElseIf (ErrorCount = 3) Then
MessageBox.Show(" You have exceeded the maximum login attempts. System is now exiting. ", " Error! ", MessageBoxButtons.OK, MessageBoxIcon.Error)
'The system will then exit after the message box is closed
Application.Exit()
End If
End If
Catch ex As Exception
MessageBox.Show("Failed to connect to Database.", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End If
End Sub
'if you have problems ask me at 0114280#kdu-online.com'strong text
End Class