Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to send an email whenever the user is locked out. I am using ASP.NET Membership framework. Is there any way to determine or handle any event when a user Locked Out
Posted

Hello Abdhullah,

Please have a look at this MSDN documentation[^] which shows a custom implementation of WebAuthenticationFailureAuditEvent class. The MemberShip provider fires an
AuditMembershipAuthenticationFailure Web event when user login fails. The NameToAuthenticate property returns the name of the user being authenticated. You can use it to fetch the user's record to read user's email and then send out and e-mail. Please remember that the AuditMembershipAuthenticationFailure event is raised when any one of the following condition is true and hence you will also have to check whether the user is locked out or not.

  • Either the user name or password does not match
  • User is not active
  • User is locked out

Please note that the said event is raised every time there is a login failure. You can use IsLockedOut bit field of aspnet_Membership table to determine whether the user in question is locked out or not. This check itself won't be sufficient if you want to send the email only once. You need an additional check,
MSDN Membership Provider Doc#Account Locking:
How does an account become locked in the first place? Suppose the user types an incorrect password into the login page. After ascertaining that the password is invalid, CheckPassword calls the stored procedure aspnet_Membership_UpdateUserInfo to update the corresponding record in the aspnet_Membership table. It passes in a bit flag indicating an invalid password was submitted. Seeing the flag, the stored procedure increments the failed password attempt count. If the count exceeds the maximum specified by MaxInvalidPasswordAttempts, and if all the password failures occurred within the time window specified by PasswordAttemptWindow, the stored procedure sets IsLockedOut to 1, effectively locking the account until further notice. Thus, locking is handled primarily at the database level, and it is largely opaque to the provider itself.
The above doc suggests that you can check the difference between the MaxInvalidPasswordAttempts and FailedPasswordAttemptCount and if it's equal to 1 then it's the first time user is getting locked out.

Regards,
 
Share this answer
 
v2
Comments
Abdullah Al-Muzahid 24-Oct-13 7:09am    
Thank you very very much for your reply. But, the event you have mentioned is fired when an attempt to login fails due to wrong username or password, user is not approved or user is locked out. SO, if I send the email for this event then the email will be send every time whenever the locked user tries to login.
I want to send the email once - at the time when the user becomes locked out.
Prasad Khandekar 24-Oct-13 9:20am    
I have updated my solution, please check.
Hi

Thi link may help you

http://www.asp.net/web-forms/tutorials/security/admin/unlocking-and-approving-user-accounts-cs[^]

Solution 2

You may write a window service which checks up the users at a regular interval and send mail to the locked user
 
Share this answer
 
v2
Comments
Abdullah Al-Muzahid 24-Oct-13 7:03am    
Thanks for your reply. But, I am not looking for this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900