Wednesday, November 26, 2008

Unlock User in asp.net membership login system

The asp.net membership has the mechanism that it locks out a user's account if she tries to authenticate herself with false password five times, by default, or within 10 minute window. It is all for possible hacks. And I had no mechanism to unlock the user account. Because locked user can not login, I needed some way to unlock the user. Firstly, I was frustrated since I saw the MembershipUser class's IsLockedOut read only property. But later I came to know that there exists MembershipUser's UnlockUser() method that satisfies my requirement.

So here goes the tricky asp.net code.

MembershipUser user = Membership.GetUser(username);

user.UnlockUser();

The string username is the locked user's user name. You can use user's user name or providerKey [the user's unique id] to get the user detail in
MembershipUser object.

I just came across the solution and thought it would be a great help to those who have the same problem. Happy Programming! Happy dotnetting!!

kick it on DotNetKicks.com

0 comments:

Post a Comment

Hope you liked this post. You can leave your message or you can put your valuable suggestions on this post here. Thanks for the sharing and cooperation!

Popular Posts

Recent Articles