Log System with 3 attempts and block the user after 3rd attempt with time interval

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vbbeginer
    New Member
    • Jul 2012
    • 2

    #1

    Log System with 3 attempts and block the user after 3rd attempt with time interval

    I have a log in form with max attempts of 3 then the program will automatically closed, but i want to find the code to block the user to log in with a time interval..Im using VB 2008(VB.net) and MS ACCESS 2010 as back end..

    Here's my code:

    Code:
    Imports System.Data.OleDb
    Public Class LogForm
        Dim Attempt As Integer = 1
        Dim con As New OleDbConnection
    
        Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\GDPCC\gdpcc.mdb"
        End Sub
        Public Function ask()
            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            con.Open()
            Dim da As New OleDbDataAdapter("select * from gdpccTable", con)
            da.Fill(dt)
            For Each datarow In dt.Rows
                If TextBox1.Text = datarow.item(7) And TextBox2.Text = datarow(8) Then
                    con.Close()
                    Return True
    
                End If
            Next
    
            con.Close()
            Return False
    
        End Function
    
    
        Private Sub login_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login_button.Click
            If ask() = True Then
                EmpForm.Show()
                Me.Hide()
                MessageBox.Show("WELCOME '" & TextBox1.Text & "'")
                TextBox1.Text = ""
                TextBox2.Text = ""
    
            ElseIf TextBox1.Text = "" And TextBox2.Text = "" Then
                MessageBox.Show("Input Username and Password")
    
            ElseIf TextBox1.Text = "" Then
                MessageBox.Show("Input Username")
                TextBox2.Text = ""
    
            ElseIf TextBox2.Text = "" Then
                MessageBox.Show("Input Password")
                TextBox1.Text = ""
    
            ElseIf TextBox1.Text = "admin" And TextBox2.Text = "pass" Then
                MessageBox.Show("Welcome Admin!!!")
                AdminForm.Show()
                Me.Hide()
    
                TextBox1.Text = ""
                TextBox2.Text = ""
    
            ElseIf Attempt = 3 Then
                MsgBox("Maximum number of Attempts(3), Program will now Shutdown")
                TextBox1.Text = ""
                TextBox2.Text = ""
                Me.Close()
    
    
            ElseIf ask() = False Then
                MessageBox.Show("Invalid Username and Password! You currently have reached Attempt" & Attempt & " of 3.")
                Attempt = Attempt + 1
                TextBox1.Text = ""
                TextBox2.Text = ""
                TextBox1.Focus()
    
    
            End If
        End Sub
      End Class
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    There are a few ways to accomplish this; however, the most straight forward would be to have a table that logs the user name and the last time a login failed.
    From there, your login form checks that table and compares the user id attempting to login against the table to see if that name is there and if the current system time is greater than the time of the last login attempt by the amount of time you desire if the name is listed.

    -z

    Comment

    • vbbeginer
      New Member
      • Jul 2012
      • 2

      #3
      ...

      Thanks Sir! It helps!

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        I should mentioned one thing to remember is that access isn't a totaly secure program. There are ways for the user to bypass almost anything done by the programmer.
        -z

        Comment

        Working...