Yussi Ariefiyono
Lock User Manually in asp.net membership
Problem:
Users is automatically locked when he/she entered 3x or more wrong username/passwor ( its depend on what you set in web.config).
Admin need manually lock n unlock Users.
Solution:
unlock is easy, cause its already buildin method for that,
hereby the sample of code:
MembershipUser f = Membership.GetUser(UserID);
f.ChangePassword("OldPasswordHidden", "NewPasswordHidden" );
Membership.UpdateUser(f);
the tricky part is lock the user manually,
with this case, i used tableadapter
Select statement:
SELECT UserId, IsLockedOut FROM aspnet_Membership WHERE (UserId = @UserId)
Update statement:
UPDATE aspnet_Membership SET IsLockedOut = @IsLockedOut WHERE (UserId = @Original_UserId)
And for the code behind, will be:
// create new object
aspnet_MembershipTableAdapter user = new aspnet_MembershipTableAdapter();
//apply Lock method
user.UpdateLock(Convert.ToBoolean("True"), new Guid("userID"));
I hope its usefull.
| Print article | This entry was posted by yussi ariefiyono on March 30, 2009 at 5:32 pm, and is filed under asp.net. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
It is bad because some membership providers are caching.
about 1 year ago
thank for the comment.
but this post is for default asp.net membership