By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,940 Members | 611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,940 IT Pros & Developers. It's quick & easy.

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

P: 2
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Data.OleDb
  3. Public Class LogForm
  4.     Dim Attempt As Integer = 1
  5.     Dim con As New OleDbConnection
  6.  
  7.     Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.         con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\GDPCC\gdpcc.mdb"
  9.     End Sub
  10.     Public Function ask()
  11.         Dim dt As New DataTable
  12.         Dim ds As New DataSet
  13.         ds.Tables.Add(dt)
  14.         con.Open()
  15.         Dim da As New OleDbDataAdapter("select * from gdpccTable", con)
  16.         da.Fill(dt)
  17.         For Each datarow In dt.Rows
  18.             If TextBox1.Text = datarow.item(7) And TextBox2.Text = datarow(8) Then
  19.                 con.Close()
  20.                 Return True
  21.  
  22.             End If
  23.         Next
  24.  
  25.         con.Close()
  26.         Return False
  27.  
  28.     End Function
  29.  
  30.  
  31.     Private Sub login_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login_button.Click
  32.         If ask() = True Then
  33.             EmpForm.Show()
  34.             Me.Hide()
  35.             MessageBox.Show("WELCOME '" & TextBox1.Text & "'")
  36.             TextBox1.Text = ""
  37.             TextBox2.Text = ""
  38.  
  39.         ElseIf TextBox1.Text = "" And TextBox2.Text = "" Then
  40.             MessageBox.Show("Input Username and Password")
  41.  
  42.         ElseIf TextBox1.Text = "" Then
  43.             MessageBox.Show("Input Username")
  44.             TextBox2.Text = ""
  45.  
  46.         ElseIf TextBox2.Text = "" Then
  47.             MessageBox.Show("Input Password")
  48.             TextBox1.Text = ""
  49.  
  50.         ElseIf TextBox1.Text = "admin" And TextBox2.Text = "pass" Then
  51.             MessageBox.Show("Welcome Admin!!!")
  52.             AdminForm.Show()
  53.             Me.Hide()
  54.  
  55.             TextBox1.Text = ""
  56.             TextBox2.Text = ""
  57.  
  58.         ElseIf Attempt = 3 Then
  59.             MsgBox("Maximum number of Attempts(3), Program will now Shutdown")
  60.             TextBox1.Text = ""
  61.             TextBox2.Text = ""
  62.             Me.Close()
  63.  
  64.  
  65.         ElseIf ask() = False Then
  66.             MessageBox.Show("Invalid Username and Password! You currently have reached Attempt" & Attempt & " of 3.")
  67.             Attempt = Attempt + 1
  68.             TextBox1.Text = ""
  69.             TextBox2.Text = ""
  70.             TextBox1.Focus()
  71.  
  72.  
  73.         End If
  74.     End Sub
  75.   End Class
  76.  
  77.  
Jul 3 '12 #1

✓ answered by zmbd

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

Share this Question
Share on Google+
3 Replies


zmbd
Expert Mod 5K+
P: 5,397
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
Aug 13 '12 #2

P: 2
Thanks Sir! It helps!
Aug 13 '12 #3

zmbd
Expert Mod 5K+
P: 5,397
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
Aug 13 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.