Updating a value if cell is DBNull

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Denden
    New Member
    • Aug 2014
    • 33

    Updating a value if cell is DBNull

    hi, i want to know how to implement this one, im trying to do a login page in vb.net 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.

    Code:
    Dim cmd As New SqlCommand("select * from users where username=@username", conn)
    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

    Code:
            Using conn As New SqlConnection(constring)
                Try
                    conn.Open()
                    Dim cmd As New SqlCommand("select * from users where username=@username and password=@password", conn)
                    cmd.Parameters.AddWithValue("@username", TextBox1.Text.ToString)
                    cmd.Parameters.AddWithValue("@password", TextBox2.Text.ToString)
                    Dim dr = cmd.ExecuteReader
                    If dr.HasRows Then
                        Form2.Show()
                        Me.Hide()
                    Else
                        MessageBox.Show("Put some error messages here")
                    End If
    
                Catch ex As Exception
                    'do something here
                End Try
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    This particular rule is going to require more design than you currently have.

    Right now you are selecting from your users table where username=@usern ame 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.

    -Frinny

    Comment

    Working...