sanctified
Programmer
Hi Group,
The following code was written by someone else and I would like to amend so that the users account is locked after 3 unsuccessful attempts to log in. How can I amend this code? I have created a field called locked on the users table and will set it to 1 to lock the account out.
I'm new to ASP.NET and don't really understand the TRY section. I presume I would need to loop round this incrementing a counter for every unsuccessful attempt. On the 3rd attempt, bomb out ...
Dim blnValidConnection As Boolean
Dim drUserData As SqlDataReader
Dim strCommand As String
Dim strConnect As String
blnValidConnection = True
lblLoginFailed.Text = ""
strConnect = "Data Source=" & strDataSource & ";Initial Catalog=" & _
strDatabase & ";User Id=" & strDatabase & "_" & _
txtUserID.Text & ";Password=" & txtPassword.Text & ";"
strCommand = "SELECT UserID, FirstName, Surname, AccessLevel " & _
"FROM Users " & _
"WHERE NTLogin = '" & txtUserID.Text & "' AND Archived = 'N'"
connDBConnect.ConnectionString = strConnect
cmdDBCommand.Connection = connDBConnect
cmdDBCommand.CommandText = strCommand
Try
cmdDBCommand.Connection.Open()
Catch exc As Exception
blnValidConnection = False
lblLoginFailed.Text = "User ID not recognized"
End Try
If blnValidConnection Then
Try
drUserData = cmdDBCommand.ExecuteReader
drUserData.Read()
Session("AccessLevel") = drUserData("AccessLevel")
Session("ConnectionString") = strConnect
Session("Database") = strDatabase
Session("NTLogin") = UCase(txtUserID.Text)
Session("UserID") = drUserData("UserID")
Session("UserName") = drUserData("FirstName") & " " & drUserData("Surname")
Session("FirstName") = drUserData("FirstName")
Session("Surname") = drUserData("Surname")
Session("intloginstatus") = 1
drUserData.Close()
cmdDBCommand.CommandText = "pbay_CheckPasswordExpiry"
cmdDBCommand.CommandType = CommandType.StoredProcedure
cmdDBCommand.Parameters.Clear()
cmdDBCommand.Parameters.Add("@pUserID", Session("UserID"))
cmdDBCommand.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
cmdDBCommand.Parameters("RETURN_VALUE").Direction = ParameterDirection.ReturnValue
cmdDBCommand.ExecuteNonQuery()
Session("DaysToExpiry") = cmdDBCommand.Parameters("RETURN_VALUE").Value()
cmdDBCommand.Connection.Close()
Response.Redirect("Parkmain.aspx")
Catch Exc As Exception
lblLoginFailed.Text = "User ID/Password not recognized"
End Try
End If
End Sub
The following code was written by someone else and I would like to amend so that the users account is locked after 3 unsuccessful attempts to log in. How can I amend this code? I have created a field called locked on the users table and will set it to 1 to lock the account out.
I'm new to ASP.NET and don't really understand the TRY section. I presume I would need to loop round this incrementing a counter for every unsuccessful attempt. On the 3rd attempt, bomb out ...
Dim blnValidConnection As Boolean
Dim drUserData As SqlDataReader
Dim strCommand As String
Dim strConnect As String
blnValidConnection = True
lblLoginFailed.Text = ""
strConnect = "Data Source=" & strDataSource & ";Initial Catalog=" & _
strDatabase & ";User Id=" & strDatabase & "_" & _
txtUserID.Text & ";Password=" & txtPassword.Text & ";"
strCommand = "SELECT UserID, FirstName, Surname, AccessLevel " & _
"FROM Users " & _
"WHERE NTLogin = '" & txtUserID.Text & "' AND Archived = 'N'"
connDBConnect.ConnectionString = strConnect
cmdDBCommand.Connection = connDBConnect
cmdDBCommand.CommandText = strCommand
Try
cmdDBCommand.Connection.Open()
Catch exc As Exception
blnValidConnection = False
lblLoginFailed.Text = "User ID not recognized"
End Try
If blnValidConnection Then
Try
drUserData = cmdDBCommand.ExecuteReader
drUserData.Read()
Session("AccessLevel") = drUserData("AccessLevel")
Session("ConnectionString") = strConnect
Session("Database") = strDatabase
Session("NTLogin") = UCase(txtUserID.Text)
Session("UserID") = drUserData("UserID")
Session("UserName") = drUserData("FirstName") & " " & drUserData("Surname")
Session("FirstName") = drUserData("FirstName")
Session("Surname") = drUserData("Surname")
Session("intloginstatus") = 1
drUserData.Close()
cmdDBCommand.CommandText = "pbay_CheckPasswordExpiry"
cmdDBCommand.CommandType = CommandType.StoredProcedure
cmdDBCommand.Parameters.Clear()
cmdDBCommand.Parameters.Add("@pUserID", Session("UserID"))
cmdDBCommand.Parameters.Add("RETURN_VALUE", SqlDbType.Int)
cmdDBCommand.Parameters("RETURN_VALUE").Direction = ParameterDirection.ReturnValue
cmdDBCommand.ExecuteNonQuery()
Session("DaysToExpiry") = cmdDBCommand.Parameters("RETURN_VALUE").Value()
cmdDBCommand.Connection.Close()
Response.Redirect("Parkmain.aspx")
Catch Exc As Exception
lblLoginFailed.Text = "User ID/Password not recognized"
End Try
End If
End Sub