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

Updating a value if cell is DBNull

P: 33
hi, i want to know how to implement this one, im trying to do a login page in and after 3 consecutive login attempts, the username will be locked and will not be able to login to the system.

inside my database, i have three columns, the username, password, and loginattempst column.

Expand|Select|Wrap|Line Numbers
  1. Dim cmd As New SqlCommand("select * from users where username=@username", conn)
  2. cmd.Parameters.AddWithValue("@username", TextBox1.Text)
so the above code selects the username from my database, but my problem is how to read the item on the loginattempts column. I heard about data reader but i dont know yet how to use it properly. This is actually code using datareader on my form

Expand|Select|Wrap|Line Numbers
  1.         Using conn As New SqlConnection(constring)
  2.             Try
  3.                 conn.Open()
  4.                 Dim cmd As New SqlCommand("select * from users where username=@username and password=@password", conn)
  5.                 cmd.Parameters.AddWithValue("@username", TextBox1.Text.ToString)
  6.                 cmd.Parameters.AddWithValue("@password", TextBox2.Text.ToString)
  7.                 Dim dr = cmd.ExecuteReader
  8.                 If dr.HasRows Then
  9.                     Form2.Show()
  10.                     Me.Hide()
  11.                 Else
  12.                     MessageBox.Show("Put some error messages here")
  13.                 End If
  15.             Catch ex As Exception
  16.                 'do something here
  17.             End Try
Oct 30 '14 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,731
This particular rule is going to require more design than you currently have.

Right now you are selecting from your users table where username=@username and if one is returned you show Form2.

If there is no row with the user name, then the user can't log in and they failed their log-in attempt.

In this case you need to somehow track the number of failed log-in attempts.

If you are planning on storing the failed login attempts in the user's row and there is no row found that matches the user, then how are you going to retrieve the amount of failed log-in attempts for the user?

In your case I would set counter in memory (instead of in the database) and once it gets to 3 the application would close.

However, that would not prevent the user from opening the application and attempting 3 more times to log in.

So, you are going to have to design a solution that takes all of these factors into consideration.

Oct 30 '14 #2

Post your reply

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