Saturday, February 25, 2017

Login System With Three Times Attempt in Visual Basic 6 and Microsoft Access

In this article I would like to share with you guys the work of my best friend and fellow software engineer Mr. Dave Marcellana from Talisay City, Negros Occidental. This program we called Login System with Three Times Attempt in Visual Basic 6 and Microsoft Access which allows the user to login and it will stop the user if the given username and password is not correct in the three attempts that the user committed to the application. The program code is very simple and short very easy to understand and user. 

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output



Directory Structure




Database and Table Structure


Program Listing


Form1

Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
   If modUserLogin.UserLogin(Text1.Text, Text2.Text) = True Then
           
      MsgBox "Welcome " & rs!Role & "!", vbInformation + vbOKOnly, "Access Granted"
    End If
End If
End Sub


modMain.bas

Public rs As New ADODB.Recordset
Public cn As New ADODB.Connection
Public sql As String
Public dbpath As String

Sub main()
Set rs = New ADODB.Recordset
Set cn = New ADODB.Connection

With rs
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
End With

dbpath = App.Path & "\database\database.mdb"

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & dbpath & ";Persist Security Info=False"
Form1.Show
End Sub

modUserLogin.bas

Public Function UserLogin(user As String, pass As String) As Boolean
If rs.State = 1 Then rs.Close

    sql = "SELECT * FROM tblSecurity WHERE Username='" & user & "'" & "AND Password ='" & pass & "'"
    rs.Open sql, cn
    'rs.Open sql, cn
    
If Not rs.EOF Then
    If rs!Role = "Administrator" Then
        UserLogin = True
    Else
        UserLogin = True
    End If
Else
    'frmLogin.fraError.Visible = True
    MsgBox "Wrong Username or Password! Try Again!", vbExclamation + vbOKOnly, "Access Denied"
    UserLogin = False
    Form1.lblcount.Caption = Form1.lblcount.Caption + 1
    
    a = Form1.lblcount.Caption

    If a > 2 Then
    MsgBox "Sorry! You've reached the maximum retries for entering a user account. The system will be closed.", vbCritical + vbOKOnly, "Access Denied"
    End
    End If

End If
End Function




No comments:

Post a Comment