| Install | |
|---|---|
composer require rappasoft/laravel-authentication-log |
|
| Latest Version: | v6.0.1 |
| PHP: | ^8.1 |

Laravel Authentication Log is a comprehensive package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, Device Fingerprint, etc. It sends out notifications via mail, slack, or SMS for new devices and failed logins, detects suspicious activity, provides session management, prevents duplicate log entries from session restorations, and much more.
Version 6.0.0 introduces major enhancements including session restoration prevention, improved device fingerprinting, enhanced statistics, and more. See the Release Notes for complete details.
See the documentation for detailed installation and usage instructions.
| Laravel | Authentication Log | Features |
|---|---|---|
| 8.x | 1.x | Basic logging only |
| 9.x | 2.x | Basic logging only |
| 10.x | 3.x | Basic logging only |
| 11.x | 5.x, 6.x | All features (device fingerprinting, suspicious activity, webhooks, session management, etc.) |
| 12.x | 5.x, 6.x | All features (device fingerprinting, suspicious activity, webhooks, session management, etc.) |
Note: Version 6.x requires Laravel 11.x or 12.x and PHP 8.1+. Version 5.x also supports Laravel 11.x and 12.x. For Laravel 10.x support, please use version 3.x.
composer require rappasoft/laravel-authentication-log
use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable;
class User extends Authenticatable
{
use AuthenticationLoggable;
}
For new installations:
php artisan vendor:publish --provider="Rappasoft\LaravelAuthenticationLog\LaravelAuthenticationLogServiceProvider" --tag="authentication-log-migrations"
php artisan migrate
For existing installations (upgrading from v5.x or earlier):
# Update the package
composer update rappasoft/laravel-authentication-log
# Publish the upgrade migration (if upgrading from v3.x or earlier)
php artisan vendor:publish --provider="Rappasoft\LaravelAuthenticationLog\LaravelAuthenticationLogServiceProvider" --tag="authentication-log-migrations"
# Run the migrations (the upgrade migration will only add columns if they don't exist)
php artisan migrate
Important: If upgrading from v3.x or earlier, the upgrade migration will safely add the new columns (device_id, device_name, is_trusted, last_activity_at, is_suspicious, suspicious_reason) to your existing authentication_log table without affecting existing data.
Breaking Changes in v6.0.0:
php artisan vendor:publish --provider="Rappasoft\LaravelAuthenticationLog\LaravelAuthenticationLogServiceProvider" --tag="authentication-log-config"
$user = User::find(1);
// Get comprehensive statistics
$stats = $user->getLoginStats();
// Returns: total_logins, failed_attempts, unique_devices, unique_ips, last_30_days, etc.
// Or get individual stats
$totalLogins = $user->getTotalLogins();
$failedAttempts = $user->getFailedAttempts();
$uniqueDevices = $user->getUniqueDevicesCount();
// Get all active sessions
$activeSessions = $user->getActiveSessions();
$sessionCount = $user->getActiveSessionsCount();
// Revoke a specific session
$user->revokeSession($sessionId);
// Revoke all other sessions (keep current device)
$user->revokeAllOtherSessions($currentDeviceId);
// Revoke all sessions
$user->revokeAllSessions();
// Get all user devices
$devices = $user->getDevices();
// Trust a device
$user->trustDevice($deviceId);
// Untrust a device
$user->untrustDevice($deviceId);
// Update device name
$user->updateDeviceName($deviceId, 'My iPhone');
// Check if device is trusted
if ($user->isDeviceTrusted($deviceId)) {
// Device is trusted
}
use Rappasoft\LaravelAuthenticationLog\Models\AuthenticationLog;
// Filter successful logins
$successfulLogins = AuthenticationLog::successful()->get();
// Filter failed logins
$failedLogins = AuthenticationLog::failed()->get();
// Filter by IP address
$ipLogs = AuthenticationLog::fromIp('192.168.1.1')->get();
// Filter recent logs (last 7 days)
$recentLogs = AuthenticationLog::recent(7)->get();
// Filter suspicious activities
$suspicious = AuthenticationLog::suspicious()->get();
// Filter active sessions
$activeSessions = AuthenticationLog::active()->get();
// Filter trusted devices
$trustedDevices = AuthenticationLog::trusted()->get();
// Filter by device ID
$deviceLogs = AuthenticationLog::fromDevice($deviceId)->get();
// Filter for specific user
$userLogs = AuthenticationLog::forUser($user)->get();
// Detect suspicious activity
$suspiciousActivities = $user->detectSuspiciousActivity();
// Returns array of suspicious activities:
// [
// [
// 'type' => 'multiple_failed_logins',
// 'count' => 5,
// 'message' => '5 failed login attempts in the last hour'
// ],
// [
// 'type' => 'rapid_location_change',
// 'countries' => ['US', 'UK'],
// 'message' => 'Login from multiple countries within an hour'
// ]
// ]
use Rappasoft\LaravelAuthenticationLog\Middleware\RequireTrustedDevice;
// In your routes file
Route::middleware(['auth', RequireTrustedDevice::class])->group(function () {
// These routes require a trusted device
Route::get('/sensitive-action', [Controller::class, 'sensitiveAction']);
});
# Export all logs to CSV
php artisan authentication-log:export --format=csv
# Export to JSON
php artisan authentication-log:export --format=json
# Specify custom output path
php artisan authentication-log:export --format=csv --path=storage/app/logs.csv
Add webhooks to your config/authentication-log.php:
'webhooks' => [
[
'url' => 'https://example.com/webhook',
'events' => ['login', 'failed', 'new_device', 'suspicious'],
'headers' => [
'Authorization' => 'Bearer your-token',
],
],
],
The package includes comprehensive configuration options:
See the configuration documentation for all available options.
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.