3 Replies - 302 Views - Last Post: 28 January 2013 - 06:29 PM Rate Topic: -----

#1 jonbon004  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 12-July 12

hello can anyone here can help my simple problem?

Posted 27 January 2013 - 11:35 PM

Here is my code and what I expecting outcome is it will count the log in counts and when the counts reach 3 it will be banned for 3 minutes.

I put it inside the loginButton.clicked

Dim a As Integer = 0
 If userTextbox.Text = "username" And passTextbox.Text = "password" Then
  MsgBox("Welcome!")
 Else If userTextbox.Text <> "username" And passTextbox.Text = "password" Then
  a += 1
  MsgBox("Username wrong!")
 Else If userTextbox.Text = "username" And passTextbox.Text <> "password" Then
  a += 1
  MsgBox("Password wrong!")
 Else
  a += 1
  MsgBox("Username and Password are Incorrect.")
 End If
 If a = 3 Then
   MsgBox("Your account is banned for 3 mins. please wait")
 End If

This post has been edited by AdamSpeight2008: 28 January 2013 - 08:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: hello can anyone here can help my simple problem?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4399
  • View blog
  • Posts: 12,255
  • Joined: 18-April 07

Re: hello can anyone here can help my simple problem?

Posted 27 January 2013 - 11:55 PM

For general practice in security it is best never to tell the user if it was their username or password that is wrong. This is because if someone is attacking the login and you are saying the username is incorrect a bunch of times and then suddenly tell the user that password is incorrect the attacker now knows a valid username to attack.

Always use the line Your username and/or password is incorrect, please try again. That way the attacker never really knows if either of them is actually valid.

Also the code you are presenting there is done in VB6 old syntax and is not how it is done anymore in VB.NET. For instance MsgBox should now be MessageBox.Show("message")

So if you put this together you should have something like...

Dim count as integer = 0

If count < 3 then
   If userTextbox.text = "username" and passTextbox.text = "password" then
       MessageBox.Show("Welcome!")
   Else
       MessageBox.Show("Your username and/or password is incorrect. Please try again.")
       count += 1
   End if
Else
   MessageBox.Show("You have been banned for 3 minutes.")
   ' Start timer if it hasn't been started, otherwise leave event
   ' At end of timer, reset count back to 0
End if



This code above assumes you have it tied into a login button event some how. :)
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3721
  • View blog
  • Posts: 12,957
  • Joined: 12-December 12

Re: hello can anyone here can help my simple problem?

Posted 28 January 2013 - 01:37 AM

The reason your original code wasn't working is because If..ElseIf requires ElseIf to be one word.

http://msdn.microsof...y/752y8abs.aspx

This post has been edited by andrewsw: 28 January 2013 - 01:38 AM

Was This Post Helpful? 1
  • +
  • -

#4 jonbon004  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 12-July 12

Re: hello can anyone here can help my simple problem?

Posted 28 January 2013 - 06:29 PM

View PostMartyr2, on 27 January 2013 - 11:55 PM, said:

For general practice in security it is best never to tell the user if it was their username or password that is wrong. This is because if someone is attacking the login and you are saying the username is incorrect a bunch of times and then suddenly tell the user that password is incorrect the attacker now knows a valid username to attack.

Always use the line Your username and/or password is incorrect, please try again. That way the attacker never really knows if either of them is actually valid.

Also the code you are presenting there is done in VB6 old syntax and is not how it is done anymore in VB.NET. For instance MsgBox should now be MessageBox.Show("message")

So if you put this together you should have something like...

Dim count as integer = 0

If count < 3 then
   If userTextbox.text = "username" and passTextbox.text = "password" then
       MessageBox.Show("Welcome!")
   Else
       MessageBox.Show("Your username and/or password is incorrect. Please try again.")
       count += 1
   End if
Else
   MessageBox.Show("You have been banned for 3 minutes.")
   ' Start timer if it hasn't been started, otherwise leave event
   ' At end of timer, reset count back to 0
End if



This code above assumes you have it tied into a login button event some how. :)/>





Thank you very much for your helpful tips and a very quick response. . . Good day! =D

View Postandrewsw, on 28 January 2013 - 01:37 AM, said:

The reason your original code wasn't working is because If..ElseIf requires ElseIf to be one word.

http://msdn.microsof...y/752y8abs.aspx

Yes! that is also my code error. . thank you! =D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1