$ show rappasoft/laravel-authentication-log
This is a Laravel package/library that provides comprehensive authentication logging and security monitoring capabilities. The package hooks into Laravel's authentication events (Login, Failed, Logout, OtherDeviceLogout) to track user authentication activity including IP addresses, user agents, device fingerprints, and location data. It provides session management (view/revoke sessions), device trust management, suspicious activity detection (multiple failed logins, rapid location changes, unusual login times), notifications via email/Slack/SMS, webhook support, and export functionality (CSV/JSON). The architecture follows Laravel conventions with event listeners, a trait for user models, query scopes, and CLI commands. The codebase demonstrates solid engineering practices with comprehensive test coverage (76 tests), proper type hints, modern PHP 8.2+ features, and clean separation of concerns.
The LLM identified 5 files worth highlighting for reuse:
A well-crafted helper that generates consistent device fingerprints by normalizing user agent strings to prevent false 'new device' notifications when browsers update. Uses SHA-256 hashing combining normalized user agent, IP address, and HTTP headers. Extracts browser and OS information from user agents. Self-contained, testable, and could be extracted to another project with minimal modification.
A comprehensive trait that adds authentication logging capabilities to any Laravel model. Provides relationships (authentications, latestAuthentication), statistics methods (getLoginStats, getTotalLogins, etc.), session management (revokeSession, revokeAllOtherSessions), device management (trustDevice, untrustDevice), and suspicious activity detection. Well-documented with PHPDoc, returns CarbonInterface for compatibility with immutable date casting, and demonstrates non-obvious skill in handling edge cases like session restoration prevention.
A clean, reusable rate limiting helper using Laravel's Cache facade. Prevents notification spam with configurable max attempts and decay periods. Simple interface with shouldSend, reset, and getRemainingAttempts methods. Could be extracted and applied to other notification systems with minimal adaptation. Demonstrates good separation of concerns and testability.
A well-structured service for sending webhooks to external services on authentication events. Configurable endpoints with event filtering, headers, and timeout settings. Includes proper error handling with logging of failures. Could be reused in other packages needing webhook functionality. Demonstrates solid engineering practices with try-catch blocks and graceful degradation.
A sophisticated event listener that handles login events with session restoration prevention (fixes duplicate log entries from page refreshes/remember me cookies). Detects suspicious activity, sends notifications with rate limiting, and triggers webhooks. The session restoration logic is particularly well-crafted, using last_activity_at to anchor the window rather than login_at, preventing continuously-active sessions from spawning duplicate entries. Shows non-obvious skill in handling Laravel's session behavior.