curveball / a12n-server

An open source lightweight OAuth2 server
Apache License 2.0
448 stars 49 forks source link

Block user accounts if an incorrect password was entered 5 times #527

Open YunhwanJeong opened 1 week ago

YunhwanJeong commented 1 week ago

Feature Overview:

Screenshot 2024-09-09 at 11 26 04 PM

Key Changes:

  1. Login Activity Tracking:
    • Introduced a new user_login_activity table to store login-related activities, including failed attempts and account lock status.
    • Added a new service (src/login-activity/service.ts) to handle the logic related to tracking failed login attempts and locking accounts.
  2. Account Locking Logic:
    • Implemented a maximum failed attempts limit. If the login attempt is made when the account is locked, increment the failed_login_attempts and create log entry with the loginFailedAccountLocked event.
    • If the limit is reached, the account is immediately locked, and a log entry is created with the accountLocked event.
    • Users with locked accounts are presented with an appropriate error message, instructing them to contact the administrator to unlock their account.
  3. Resetting Failed Attempts:
    • After a successful login, the failed attempts counter is reset to ensure that future incorrect password attempts are tracked accurately.
  4. Controller Enhancements:
    • Updated the post method in the login controller to incorporate the new login activity tracking and account locking logic.
    • Ensured that the resetFailedLoginAttempts function is executed after a successful login to maintain data integrity.
  5. Logging:
    • Enhanced logging to include new events such as loginFailedAccountLocked and accountLocked, providing better visibility into account security incidents.

Security Improvements:

This feature improves the security of user accounts by preventing brute-force attacks and unauthorized access through repeated incorrect password attempts.

Testing & Validation:

Next Steps:

Checklist