Hi Guys, I really need a help on this issue.. I have the same problem here..
i need to enhance the existing code to add on the user locked if the user failed 3 times... even after they enter the username & password, the system should track whether the user have been tried to login before... once it have been try for three times, the user should be locked by system , administrator should unlock the user account.. please help me... thanks...
Currently, below are my coding.... please help me to find out where did i go wrong... Thanks so much.....
Option Explicit
Dim g_objRSx As ADODB.Recordset
Private Sub cmdCancel_Click()
'set the global var to false
'to denote a failed login
LoginSucceeded = False
loginUserType = ""
Me.Hide
End Sub
Private Sub cmdOK_Click()
'check for correct password
loginfailed_cnt = loginfailed_cnt + 1
If chkpassword = True Then
'setting a global var is the easiest
LoginSucceeded = True
'update the tblog table for good login
Loginstatus ("Successful")
Me.Hide
Else
If loginfailed_cnt = 3 Then
Loginstatus ("3 invalid logins")
MsgBox "You have made 3 invalid attempts. Bye..."
Unload frmLogin
Unload frmmainmenu1
Exit Sub
End If
txtPassword.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Function chkpassword() As Boolean
Dim sqlline As String
Set g_objRSx = New ADODB.Recordset
sqlline = "SELECT USERTYPE, USERNAME " _
+ "FROM TBUSER " _
+ "WHERE [USERID] = " & cnvuserid() & " AND" _
+ " [USERPWD] = " & cnvuserpwd & ""
g_objRSx.Open sqlline, g_objConn, adOpenStatic, adLockReadOnly
If g_objRSx.RecordCount > 0 Then
'chkpassword = True
g_objRSx.MoveFirst
Do Until g_objRSx.EOF
'Assign the access level in the public variable
loginUserType = Trim(UCase(g_objRSx!UserType.Value))
g_objRSx.MoveNext
Loop
On Error GoTo 0
Else
MsgBox "login failed, pls try again OR contact your Administrator"
g_objRSx.Close
loginUserType = ""
chkpassword = False
Exit Function
End If
g_objRSx.Close
chkpassword = True
End Function
Function cnvuserid() As String
Dim xstr As String
xstr = "'" & UCase(Trim(txtUserName.Text)) & "'"
cnvuserid = xstr
End Function
Function cnvuserpwd() As String
Dim xxstr As String
xxstr = "'" & UCase(Trim(txtPassword.Text)) & "'"
cnvuserpwd = xxstr
End Function
Function cnvlogdate() As String
'' to get the current date
'cnvlogdate = "CDATE(" & "'" & Trim(Format(Date, "dd-mm-yyyy")) & "'" & ")"
'cnvlogdate = "CDATE(" & "'" & Trim(FormatDateTime(Date, vbGeneralDate)) & "'" & ")"
cnvlogdate = Trim(FormatDateTime(Date, vbGeneralDate))
'FormatDateTime(Date[,NamedFormat])
End Function
Function cnvXwhat(Xwhat) As String
'' to get the current date
cnvXwhat = "'" & UCase(Trim(Xwhat)) & "'"
End Function
Function Loginstatus(Xwhat As String)
Dim mStr As String
Dim Sqlline1 As String
Dim mydate, mytime
mydate = Format(Now, "dd-mmm-yyyy")
mytime = Time
mStr = Trim(UCase(Xwhat))
Set g_objRSx = New ADODB.Recordset
g_objConn.Execute " INSERT INTO TBLOG " _
& "(DTLOGDATE, DTLOGTIME, SUSERID, SLOGDESC) " _
& "VALUES ('" & mydate & "','" & mytime & "'," & cnvuserid() & "," _
& cnvXwhat(Xwhat) & ");"
End Function