Results 1 to 7 of 7

Thread: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    95

    [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    Good eve/day guys! our defense is finish but our teacher suggest that if the user input invalid username or password 3 times it will block the user to log in.... I have a code here and it's working BUT i'm not satisfied on my code.... I FEEL it is not the proper way to code....

    it is possible to use a timer to do it's job?

    Code:
    Public Class AdminForm
    
        Public Attempt As Integer
        Dim prevAttemptTime As Date
        Dim curAttemptTime As Date
        Dim blockUserLogin As Integer
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim minDiff As Integer = DateDiff(DateInterval.Minute, prevAttemptTime, curAttemptTime)
            Dim secDiff As Integer = DateDiff(DateInterval.Second, prevAttemptTime, curAttemptTime)
            curAttemptTime = TimeOfDay
            If minDiff < 1 And blockUserLogin = 1 Then ' I set it to 1 min just to test if my code is working
                MsgBox("You're still unable to login. Please try again later." & vbNewLine & "Elapsed Time: " & minDiff & " min(s). " & secDiff & " sec(s).")
            Else
                If TextBox1.Text <> "admin" Or TextBox2.Text <> "password" Then ' It's only a dummy
                    Attempt += 1
                    If Attempt = 3 Then
                        blockUserLogin = 1
                        prevAttemptTime = TimeOfDay
                        MsgBox("You entered 3 consecutive invalid username and password. Please try again after 10 mins.", MsgBoxStyle.OkOnly)
                        TextBox1.Clear()
                        TextBox2.Clear()
                        Attempt = 0
                    Else
                        MsgBox("Invalid Username or Password. Please try again.", MsgBoxStyle.OkOnly)
                        TextBox1.Clear()
                        TextBox2.Clear()
                    End If
                Else
                    Form1.DailyReportToolStripMenuItem.Enabled = True
                    Form1.MonthlyReportToolStripMenuItem.Enabled = True
                    'Form1.ShowLoggedInReportToolStripMenuItem.Enabled = True
                    'Form1.LoggedInReportToolStripMenuItem.Enabled = True
                    Form1.YouMustLogInToolStripMenuItem.Visible = False
                    Form1.ConsolidatedReportToolStripMenuItem.Enabled = True
                    TextBox1.Clear()
                    TextBox2.Clear()
                    Form1.LogInToolStripMenuItem.Enabled = False
                    Form1.LogoutToolStripMenuItem.Enabled = True
                    MsgBox("College Library User Attendance System!", MsgBoxStyle.OkOnly, "Welcome")
                    Me.Close()
                End If
            End If
        End Sub
    End Class
    blockUserLogin - it means if the value is 1 the system will block the user until 10 min. past

    EDIT:

    any suggestion code? please feel free to post your suggestion code here.
    Last edited by MeSH; Mar 4th, 2015 at 08:47 AM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    I've moved this thread into the code it better forum as that is where it should go.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    95

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    thanks for moving... I never thought there is a thread for this.... btw what are the difference between VB.NET thread to this Code it better thread sir?

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    The VB.Net Forum is designed for questions or discussions specifically on Visual Basic.Net where as the Code It Better forums is designed for any language that has a working piece of code but would like for the code to be improved.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    95

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    thank you for the clarification sir... but I think this thread has less viewer than in the VB.NET... so it has low chance to notice my thread

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    A lot of viewers look at the what's new view which show threads with the newest post. So you're at the top right now!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    95

    Re: [WORKING] Block a User if log in attempt reach 3 times. [BUT] need PROPER code

    bump!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width