Imports System.Data.OleDb
Imports System.Data
Public Class Password1
    Dim Pass2Connection As OleDbConnection
    Dim Pass2Command As OleDbCommand
    Dim Pass2Table As New DataTable
    Dim Pass2Adapter As OleDbDataAdapter
    Dim Pass2Manager As CurrencyManager

    Dim NumTries As String ' This variable contains Number that the user will enter password
    Private Sub Password1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Pass2Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Pass2.mdb")
        Pass2Connection.Open()
        Pass2Command = New OleDbCommand("SELECT * FROM Pass2 ORDER BY Passe", Pass2Connection)
        Pass2Adapter = New OleDbDataAdapter()
        Pass2Adapter.SelectCommand = Pass2Command
        Pass2Table = New DataTable()
        Pass2Adapter.Fill(Pass2Table)

    End Sub

    Private Sub BtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnter.Click
        NumTries += 1

        Pass2Table.DefaultView.Sort = "Passe"
        Dim FoundRow As Integer = Pass2Table.DefaultView.Find(Password.Text)

        Pass2Table.DefaultView.Sort = "UserName"
        Dim FindRow As Integer = Pass2Table.DefaultView.Find(UserName.Text)

        If FoundRow <> -1 And FindRow <> -1 Then

            CompanyDetails.Show()
            Me.Hide()



        ElseIf NumTries < 3 Then
            MsgBox("Invalid Password!Please try again" & vbCr & "Or the Field Is Empty.", MsgBoxStyle.Critical, )
            UserName.Text = ""
            Password.Text = ""
        ElseIf NumTries >= 3 Then
            Beep()
            MsgBox("You are Not Autorized to use this Program!", MsgBoxStyle.Exclamation)
            UserName.Enabled = False
            Password.Enabled = False
            UserName.Text = ""
            Password.Text = ""
            BtnEnter.Enabled = False
            Me.Hide()
            ATarification.Show()

        End If

    End Sub
End Class