954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

user locked out after 3 tries in vb 6.0

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...

priya2278
Newbie Poster
2 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Are you using any database? Are you keeping the details of user name and password in DB?

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

you need to store user details in DB.

1. check the status of the use account with each login.
2. increment the counter by 1 with each failed login.
3. update the status of the user to locked once the counter reaches 3.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

yes im using sql database to store the user name and password.. i have done the increment by 1 and after it reach 3 (the message box will appear said "Please contact administrator") ... after the 3 times, the user still can access into the system.... how should I prevent the user from login into the system after 3 times...

priya2278
Newbie Poster
2 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

read point #1 of my previous post.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Yes as debasis said, Have one column like Status or somthing, Update it to Incactive if attemt reaches to 3+ and check this status while ur doing validation when user hits on logon button. If Status is Inactive give message and exit..

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

i think you are only displaying the message, but actually not locking the user on 3 failed login attempts.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Module .bas

Public path As String


Sub Main()


Set db = New ADODB.Connection

path = App.path & "\Data\yourdb.mdb"
db.CursorLocation = adUseClient
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & path

frmODBCLogon.Show
End Sub


frmODBCLogon (Form)

Private Sub CmdOk_Click()
Set rs = New ADODB.Recordset
Static countx
Static CountY
CountY = 1
If txtUserName.Text <> "" And txtPassword.Text <> "" Then
    rs.Open "Select * from Users where Username ='" & CStr(txtUserName.Text) & "' and Password ='" & CStr(txtPassword.Text) & "'", db, 2, 3
        If rs.EOF Then
            MsgBox "User authentication Failed!Invalid username or password! Please Try Again!", vbExclamation, "INVALID ACCOUNT"
            countx = countx + CountY
                If countx = 3 Then
                    MsgBox "Please contact administrator!", vbCritical, "ERROR"
                    
                    'Locked the user's status account
                    Dim stat As String
            
                    stat = "locked"
                    
                     db.Execute ("Update [Users] set [Status]='" & stat & "' WHERE [Username]='" & txtUserName.Text & "'")
                End If
                
            countx = countx
            txtUserName.Text = ""
            txtPassword.Text = ""
            txtUserName.SetFocus
        Else
           
            Unload Me
            MsgBox "Access Granted!!"
            
            With frmMain
             
                .Show
            End With
        End If
    rs.Close
Else
    MsgBox "Cannot Login! Insert Username/Password!", vbExclamation, "ERROR"
    txtUserName.SetFocus
End If
End Sub
emond
Newbie Poster
14 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

All you really need is a few conditionals with your events in between as such:

dim attempts as integer

attempts = 0

private sub Login()
if attempts <= 3 then
		if username = "username" and password = "password" then
			'login
		else
			attempts = attempts + 1
		end if
else
'contact systems admin
end if

End sub



private sub Reset()
	If adminUser = "adminUser" and adminPass = "adminPass" then
		attempts = 0
	end if
End sub


PM me if this is helpful so i know im posting working stuff and not complete gibberish

OblibSystems
Junior Poster in Training
65 posts since Aug 2011
Reputation Points: 22
Solved Threads: 0
 

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

reshmika
Newbie Poster
1 post since Apr 2012
Reputation Points: 0
Solved Threads: 0
 

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: