Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Inherits System.Windows.Forms.Form
- Dim mypath = Application.StartupPath & "\db1.accdb"
- Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\db1.accdb;Persist Security Info=False;")
- Dim cmd As OleDbCommand
- Dim cmd2 As OleDbCommand
- Dim cmdGetIdentity = New OleDbCommand()
- Private WrongPassword As Integer = 0
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim sql = "SELECT username,password FROM admin WHERE username = '" & TextBox1.Text & "' AND password = '" & TextBox2.Text & "'"
- Dim Sql2 = "INSERT INTO audit (Date,login_time,username,accounttype) VALUES('" + DateTimePicker1.Text + "', '" + Label5.Text + "', '" + TextBox1.Text + "', '" + TextBox3.Text + "')"
- cmd = New OleDbCommand(sql, connection)
- cmd2 = New OleDbCommand(Sql2, connection)
- connection.Open()
- Dim affectedRecord As Integer
- Dim dr As OleDbDataReader = cmd.ExecuteReader
- Try
- connection.Open()
- affectedRecord = cmd2.ExecuteNonQuery()
- If affectedRecord = 0 Then
- MessageBox.Show("No Record was Updated")
- End If
- Catch ex As InvalidOperationException
- End Try
- Try
- If dr.Read = False Then
- TextBox1.Text = ""
- TextBox2.Text = ""
- WrongPassword = WrongPassword + 1
- If WrongPassword = 1 Then
- MsgBox("WRONG PASSWORD", vbCritical, "LOGIN FAILED")
- MsgBox("You have 2 remaining chance to enter the correct password", vbCritical + vbOKOnly, "WARNING")
- ElseIf WrongPassword = 2 Then
- MsgBox("WRONG PASSWORD", vbCritical, "LOGIN FAILED")
- MsgBox("You have 1 remaining chance to enter the correct password", vbCritical + vbOKOnly, "WARNING")
- ElseIf WrongPassword = 3 Then
- MsgBox("WRONG PASSWORD", vbCritical, "LOGIN FAILED")
- MsgBox("SORRY! you reach 3 times attempt", vbCritical + vbOKOnly, "WARNING")
- Me.Close()
- End If
- Else
- TextBox1.Clear()
- TextBox2.Clear()
- MsgBox("Login Successful", MsgBoxStyle.Information, "Administrator")
- mMenu.Show()
- Me.Hide()
- End If
- Catch ex As Exception
- End Try
- If connection.State <> ConnectionState.Closed Then
- connection.Close()
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement