1,105,214 Community Members

Ban User For 10 Minutes

Member Avatar
ryklon
Newbie Poster
24 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi!

I'm creating a feature for my software that bans the user for 10 minutes if he/she has failed to login thrice.

The problem is, I don't know how to code that.
I got ideas on how to do it but I don't know what predefined classes or functions to use.

Can you please teach me what classes or functions to use to code this feature?
I'm a complete beginner but I'm willing to learn so please help.

Thanks in advance!

Member Avatar
Reverend Jim
Noli mentula
5,394 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

You could declare some variables with class scope such as

Dim numFailed As Integer            'number of consecutive failed login attempts
Dim lastAttempt As Date             'date & time of last login attempt
Dim lastUser As String              'name of last user to try to login

In the form load event, initialize numFailed to 0 and lastUser to "". When the user tries to login, the logic would be as follows

Dim canLogin as Boolean = True

if currentUser = lastUser Then
    if numFailed = 3 Then
        if less than 10 minutes since lastAttempt Then
            canLogin = False
        end if
    end if
end if

if canLogin then
    if Login(currentUser) Then
        numFailed = 0
    else
        numFailed += 1
    end if
    lastUser = currentUser
    lastAttempt = Now()
else
    MsgBox("please wait a few minutes and try again"
end if
Member Avatar
ryklon
Newbie Poster
24 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for the reply!

Gonna try this. I'll keep you updated to what happens.

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
1
 

hello !
if you are using db with this application then make a table for example name tblLogingFail .now when ever you want to ban a user then insert data in that table fields name recID,UserID,Logindate , now after this set condition that if logintime difference is less then 10 min then dont allow user and if difference is more then 10 mint allow him to login.

Regards

Member Avatar
Reverend Jim
Noli mentula
5,394 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 643 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

The last poster (whose handle I can't spell this early before my coffee) is right. You'd have to preserve the data somehow in case the user just restarts the app. This could be through a database, file, or through My.Settings variables.

Member Avatar
ryklon
Newbie Poster
24 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi!

Ok, so here's what I have so far.
I created a simple restriction for the user if he/she fails to login thrice.

Here it is

Private Sub BanUser()

        txtEmployeeID.Text = ""

        txtPassword.Text = ""

        txtEmployeeID.Enabled = False

        txtPassword.Enabled = False

        btnLogin.Enabled = False

        MessageBox.Show("You are banned for 10 minutes because your failed login attempts is more than thrice!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        TimeRestriction.

        TimeRestriction.Start()

    End Sub

But I don't know what functions or objects to use to compare the time
of the user's last attempt and the current time on the system.

I tried this code from your code above @Reverend Jim,

Dim lastAttempt As Date

lastAttempt = Now()

but it seems that its returning the date and not the time.
And one more thing, can you please, teach me how this My.Settings variables work
because I don't have a clue on how to use it properly to store the time settings on the time restriction.

Thanks in advance!

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
1
 

hello !
Please check the attached solution , it will ban single user for 10 mints ,

Attachments WindowsApplication2.zip (68.28KB)
Member Avatar
ryklon
Newbie Poster
24 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks for the reply!

I'd check this out and post here.

Member Avatar
ryklon
Newbie Poster
24 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Got this now.

Thanks!

Question Answered as of 2 Years Ago by Reverend Jim and M.Waqas Aslam
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: