Option Explicit
Private intLoginAttempts As Long
Private Sub cmdClose_Click()
Unload Me
End
End Sub
Private Sub cmdLogin_Click()
Dim strSQL As String
Dim strUName As String
Dim strPwd As String
Dim strOperatorName As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.CursorLocation = adUseClient
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb;Persist Security Info=false"
strSQL = "SELECT * "
strSQL = strSQL & "FROM Users "
strSQL = strSQL & "WHERE Username = '" & txtUsername.Text & "' "
strSQL = strSQL & "AND Password = '" & txtPassword.Text & "' "
strSQL = strSQL & "AND Disabled = 'No'"
'UNCOMMENT NEXT LINE TO DEBUG SQL STATEMENT
'Debug.Print strSQL
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
If Not (rs.EOF) Then
strUName = rs.Fields("Username").Value
strPwd = rs.Fields("Password").Value
strOperatorName = rs.Fields("Operator").Value
End If
intLoginAttempts = intLoginAttempts + 1
If txtUsername.Text = strUName And txtPassword.Text = strPwd Then
If IsLoggedIn = False Then
IsLoggedIn = True
frmMain.Show
Unload frmLoginForm
End If
ElseIf intLoginAttempts = 1 Then
IsLoggedIn = False
frmAccessDenied.Show
frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _
"Access Denied" & vbNewLine & _
"Attempt 1 of 4."
Exit Sub
ElseIf intLoginAttempts = 2 Then
IsLoggedIn = False
frmAccessDenied.Show
frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _
"Access Denied" & vbNewLine & _
"Attempt 2 of 4."
Exit Sub
ElseIf intLoginAttempts = 3 Then
IsLoggedIn = False
frmAccessDenied.Show
frmAccessDenied.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _
"Access Denied" & vbNewLine & _
"Attempt 3 of 4."
Exit Sub
ElseIf intLoginAttempts = 4 Then
With frmAccessDenied
IsLoggedIn = False
.Show
.lblAccessDeniedCaption.Top = 40
.lblAccessDeniedCaption.Caption = "Login Credentials Mismatch." & vbNewLine & _
"Access Denied" & vbNewLine & _
"Attempt 4 of 4." & vbNewLine & _
"Accound Disabled. Contact Support."
End With
strSQL = "UPDATE Users "
strSQL = strSQL & "SET Disabled = 'Yes' "
strSQL = strSQL & "WHERE Username = '" & txtUsername.Text & "'"
conn.Execute strSQL
Exit Sub
ElseIf txtUsername.Text = strUName And txtPassword.Text = strPwd And rs.Fields("Disabled").Value = "Yes" Then
IsLoggedIn = False
frmAccountDisabled.Show
Exit Sub
ElseIf Not rs.EOF And rs.Fields("FullAccess").Value = "Yes" Then
'do nothing
Else
With frmInternalSplash
'INVENTORY MANAGER
.Frame(0).Height = "1455"
.Frame(0).Width = "1695"
.Frame(0).Top = "480"
.Frame(0).Left = "120"
.cmdAddProduct.Visible = False
.cmdDeleteProduct.Visible = False
.cmdEditProduct.Visible = False
.cmdSearchProduct.Top = "240"
.cmdSearchProduct.Left = "120"
.cmdStockControl.Top = "840"
.cmdStockControl.Left = "120"
'CLIENT MANAGER
.Frame(1).Height = "2055"
.Frame(1).Width = "1695"
.Frame(1).Top = "2040"
.Frame(1).Left = "120"
.cmdDeleteClient.Visible = False
.cmdEditClient.Top = "840"
.cmdEditClient.Left = "120"
.cmdSearchClient.Top = "1440"
.cmdSearchClient.Left = "120"
'INVOICE MANAGER
.Frame(2).Height = "1455"
.Frame(2).Width = "1695"
.Frame(2).Top = "4200"
.Frame(2).Left = "120"
'LOGOUT
.Frame(3).Height = "855"
.Frame(3).Width = "1695"
.Frame(3).Top = "2160"
.Frame(3).Left = "1920"
'NAVIGATION HINT
.Frame(4).Height = "975"
.Frame(4).Width = "1695"
.Frame(4).Top = "3120"
.Frame(4).Left = "1920"
'HIDE THE ADD/EDIT/DELETE OPERATOR OPTIONS IF YOU DONT HAVE FULL ACCESS
.Frame(5).Visible = False
End With
With frmMain
.mnuAddProduct.Visible = False
.mnuAddOperator.Visible = False
.mnuEditProduct.Visible = False
.mnuEditOperator.Visible = False
.mnuDelete.Visible = False
.mnuDeleteOperator.Visible = False
.mnuSettings.Visible = False
End With
End If
frmMain.sbStatusBar.Panels(7).Text = "Welcome to Operations Manager Pro " & strOperatorName & ", you are logged in as " & strUName & "."
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
Private Sub Form_Load()
cmdLogin.Enabled = False
End Sub
Private Sub txtPassword_Change()
If LenB(txtPassword.Text) = 0 Or LenB(txtUsername.Text) = 0 Then
cmdLogin.Enabled = False
End If
If LenB(txtPassword.Text) = 0 Then
If LenB(txtUsername.Text) = 0 Then
cmdLogin.Enabled = False
End If
End If
If LenB(txtPassword.Text) > 0 And LenB(txtUsername.Text) Then
cmdLogin.Enabled = True
End If
End Sub
Private Sub txtPassword_GotFocus()
SelectWholeTextBox txtPassword
End Sub
Private Sub txtUsername_Change()
If LenB(txtPassword.Text) = 0 Or LenB(txtUsername.Text) = 0 Then
cmdLogin.Enabled = False
End If
If LenB(txtPassword.Text) = 0 Then
If LenB(txtUsername.Text) = 0 Then
cmdLogin.Enabled = False
End If
End If
If LenB(txtPassword.Text) > 0 And LenB(txtUsername.Text) Then
cmdLogin.Enabled = True
End If
End Sub
Private Sub txtUsername_GotFocus()
SelectWholeTextBox txtUsername
End Sub