Home > ASP.Net > Auto UnLock User using Membership

Auto UnLock User using Membership

Hi all,

try this example for Unlocking Users Automatically Since we obviously don’t want our users locked out forever, and most likely we don’t want to manually unlock their accounts every time something goes wrong we need to implement some code to unlock their accounts after a set time period. In this case, I am going to lock the user out for a number of minutes equal to the password attempt window starting immediately when they are locked out.

1) Open VS 2008 and create a new web site and add new web Page

2) From ToolBox drag and Drop Login control Page

3) Right click the Login Control and select Properties, In the Properties window click the Events icon

the following code to the LoggingIn event method:

//Check to see if the current user exists
if (Membership.GetUser(Login1.UserName) != null)
 //Check to see if the user is currently locked out
 if (Membership.GetUser(Login1.UserName).IsLockedOut)
 //Get the last lockout date from the user
 DateTime lastLockout = Membership.GetUser(Login1.UserName).LastLockoutDate;
 //Calculate the time the user should be unlocked
 DateTime unlockDate = lastLockout.AddMinutes(Membership.PasswordAttemptWindow);

 //Check to see if it is time to unlock the user
 if (DateTime.Now > unlockDate)

Hope this helps

Good Luck.

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: