We help IT Professionals succeed at work.
Get Started

ASP.NET Login Attempts

Larry Brister
Last Modified: 2007-05-09
I have a login page where I want to lockout a user if their attempts > 3 with the wrong username/password

I've added a int field to my tblUsers table that I can set to 1 if they need to be locked out...I just need the code that does it

The login code I'm using is below...
  If dR("UserName") = Trim(strUserName.Text) And dR("UserPassword") = Trim(strUserPassword.Text) Then
                    Dim value As Integer = 0
                    Dim isPersistent As Boolean = True
                    Dim ticket As FormsAuthenticationTicket = New FormsAuthenticationTicket(1, strUserName.Text, DateTime.Now, DateTime.Now.AddHours(1), isPersistent, strUserName.Text, FormsAuthentication.FormsCookiePath)
                    Dim hash As String = FormsAuthentication.Encrypt(ticket)
                    Dim cookie As HttpCookie = New HttpCookie(FormsAuthentication.FormsCookieName, hash)
                    '''BLAH...BLAH...BLAH''' NAME SOME SESSION VARIABLES...    '''BLAH...BLAH...BLAH'''

                    Dim oCom2 As SqlCommand = New SqlCommand
                    oCom2.Connection = objConn

                    Dim sSQL As String
                    sSQL = "Update dbo.tblUsers "
                    sSQL = sSQL & "Set LastLogin = '" & System.DateTime.Now & "'"
                    sSQL = sSQL & " where UserID=" & CInt(Session("UserID"))
                    oCom2.CommandText = sSQL

                    FormsAuthentication.RedirectFromLoginPage(Session("UserID"), False)
                    Select Case CStr(Session("GroupDesc"))
                        Case "Management", "Office Assts", "Administrator"
                           DO SOME STUFF
                        Case "Broker", "Sales"
                            DO SOME STUFF
                        Case "Agent"
                          DO SOME STUFF
                        Case Else
                           DO SOME STUFF
                    End Select
                End If
                lblError.Visible = True
                lblError.Text = "Username/Password Incorrect"
            End If
Watch Question
Top Expert 2007
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE