Archive for March, 2009
Lock User Manually in asp.net membership
Mar 30th
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.