|
Thursday, October 18, 2007 |
| Automatically unlock a user after a specified time limit |
|
Using the ASP.NET 2.0 membership service framework, I discovered that when a user's account is locked out as a result of too many invalid login attempts, it stays locked out. I guess I expected it to unlock after 10 or 15 minutes since this is what I've seen on most sites.
I wrote some code to handle this. It's kind of scratchy but it works. You can put this in the Page_PreRender and only run it on postback.
Dim ctrlLogin As System.Web.UI.WebControls.Login ctrlLogin = CType(LoginArea.FindControl("Login1"), System.Web.UI.WebControls.Login) txtUserName = CType(ctrlLogin.FindControl("UserName"), TextBox) Dim theUser As MembershipUser = Membership.GetUser(txtUserName.Text.Trim, False) If IsNothing(theUser) = False Then If theUser.IsLockedOut = True Then Dim theUser As MembershipUser = Membership.GetUser(txtUserName.Text.Trim, False) Dim ts As TimeSpan = Now.Subtract(theUser.LastLockoutDate) If Math.Round(ts.TotalMinutes) > 10 Then theUser.UnlockUser() Else ctrlLogin.Enabled = False failureText.Text = "Your account has been locked out for 10 minutes, because of too many invalid login attempts." End If End If End If |
jeremy at 7:59 PM |
(10) Comments |
Add a comment |
Permalink
|
|
|
|