Skip to content

Commit

Permalink
Merge pull request #563 from gaepdit/login-throttling
Browse files Browse the repository at this point in the history
Add login throttling
  • Loading branch information
dougwaldron authored Dec 14, 2022
2 parents e52e117 + 3333178 commit 58368fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GECO/Login.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@
</asp:UpdatePanel>
</div>
</div>
</asp:Content>
</asp:Content>
13 changes: 12 additions & 1 deletion GECO/Login.aspx.vb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ Partial Class Login
Dim gecoUser As New GecoUser
Dim userSession As New UserSession

Dim loginResult As LoginResult = LogInUser(txtUserId.Text, txtPassword.Text, chkRememberMe.Checked, gecoUser, userSession)
Dim ipAddress As String = GetIPv4Address()

Dim loginResult As LoginResult = LogInUser(txtUserId.Text, txtPassword.Text, chkRememberMe.Checked, ipAddress, gecoUser, userSession)

Select Case loginResult
Case LoginResult.Invalid
lblMessage.Text = "Either the email is not registered or the password is incorrect. Please try again."
lblMessage.Visible = True

Case LoginResult.AccountUnconfirmed
lblUnconfirmed.Visible = True

Case LoginResult.LoginThrottled
lblMessage.Text = "Too many login attempts made. Please wait a few seconds and try again."
lblMessage.Visible = True

Case LoginResult.Success
If gecoUser.UserId = 0 Then
Response.Redirect("~/ErrorPage.aspx", False)
Expand Down Expand Up @@ -81,6 +88,10 @@ Partial Class Login

End Sub

Private Shared Function GetIPv4Address() As String
Return Net.Dns.GetHostEntry(Net.Dns.GetHostName()).AddressList.GetValue(1).ToString()
End Function

Private Sub GetUserFromSession()

Dim series As String = GetCookie(UserSessionCookie.Series)
Expand Down
8 changes: 6 additions & 2 deletions GECO/_DAL/Users/UserAccounts.vb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Imports GECO.GecoModels

Public Module UserAccounts

Public Function LogInUser(email As String, password As String, remember As Boolean, ByRef user As GecoUser, ByRef userSession As UserSession) As LoginResult
Public Function LogInUser(email As String, password As String, remember As Boolean, ipAddress As String, ByRef user As GecoUser, ByRef userSession As UserSession) As LoginResult
Dim params As SqlParameter() = {
New SqlParameter("@Email", email.Trim()),
New SqlParameter("@Password", GetMd5Hash(password)),
New SqlParameter("@CreateSession", remember)
New SqlParameter("@CreateSession", remember),
New SqlParameter("@IPAddress", ipAddress)
}
Dim result As Integer
Dim ds As DataSet = DB.SPGetDataSet("geco.LogInUser", params, result)
Expand All @@ -32,6 +33,8 @@ Public Module UserAccounts
Return LoginResult.Invalid
Case 2
Return LoginResult.AccountUnconfirmed
Case 3
Return LoginResult.LoginThrottled
Case Else
Return LoginResult.DbError
End Select
Expand All @@ -41,6 +44,7 @@ Public Module UserAccounts
Success
Invalid
AccountUnconfirmed
LoginThrottled
DbError
End Enum

Expand Down

0 comments on commit 58368fc

Please sign in to comment.