PHPackages                             rappasoft/laravel-authentication-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. rappasoft/laravel-authentication-log

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

rappasoft/laravel-authentication-log
====================================

Log user authentication details and send new device notifications.

v6.1.0(3w ago)9871.9M↓30.9%119[1 PRs](https://github.com/rappasoft/laravel-authentication-log/pulls)11MITPHPPHP ^8.2CI passing

Since Oct 1Pushed 3w ago22 watchersCompare

[ Source](https://github.com/rappasoft/laravel-authentication-log)[ Packagist](https://packagist.org/packages/rappasoft/laravel-authentication-log)[ Docs](https://github.com/rappasoft/laravel-authentication-log)[ GitHub Sponsors](https://github.com/rappasoft)[ RSS](/packages/rappasoft-laravel-authentication-log/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (16)Versions (15)Used By (11)

[![Package Logo](https://camo.githubusercontent.com/f363b6f9c8ddee5b6a6bcc459ad3fae669b239fdbe40e905268056b701babb77/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c25323041757468656e7469636174696f6e2532304c6f672e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7261707061736f66742532466c61726176656c2d61757468656e7469636174696f6e2d6c6f67267061747465726e3d686964656f7574267374796c653d7374796c655f31266465736372697074696f6e3d4c6f672b757365722b61757468656e7469636174696f6e2b64657461696c732b616e642b73656e642b6e65772b6465766963652b6e6f74696669636174696f6e732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)](https://camo.githubusercontent.com/f363b6f9c8ddee5b6a6bcc459ad3fae669b239fdbe40e905268056b701babb77/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c25323041757468656e7469636174696f6e2532304c6f672e706e673f7468656d653d6461726b267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d7261707061736f66742532466c61726176656c2d61757468656e7469636174696f6e2d6c6f67267061747465726e3d686964656f7574267374796c653d7374796c655f31266465736372697074696f6e3d4c6f672b757365722b61757468656e7469636174696f6e2b64657461696c732b616e642b73656e642b6e65772b6465766963652b6e6f74696669636174696f6e732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d6c6f636b2d636c6f736564)

[![Latest Version on Packagist](https://camo.githubusercontent.com/282f7437506231853a2dbe098bb00b236c79a668ef6cea995d380a3bebfd17e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261707061736f66742f6c61726176656c2d61757468656e7469636174696f6e2d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rappasoft/laravel-authentication-log)[![Total Downloads](https://camo.githubusercontent.com/660d12a43620bd414c55fc4e882db38fdf2ffa89abcc340fa284dfccecfbff41/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261707061736f66742f6c61726176656c2d61757468656e7469636174696f6e2d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rappasoft/laravel-authentication-log)

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. **Version 6.1.0** adds Laravel 13.x support and compatibility with immutable date casting. See the [Release Notes](RELEASE_NOTES.md) for complete details.

Features
--------

[](#features)

### Core Features

[](#core-features)

- ✅ **Authentication Logging** - Tracks all login/logout attempts with IP, user agent, location, and timestamps
- ✅ **Device Fingerprinting** - Reliable device identification using SHA-256 hashing with browser version normalization (prevents false positives)
- ✅ **New Device Detection** - Automatically detects and notifies users of new device logins
- ✅ **Failed Login Tracking** - Logs and optionally notifies users of failed login attempts
- ✅ **Location Tracking** - Optional GeoIP integration for location data
- ✅ **Session Restoration Prevention** - Automatically prevents duplicate log entries from page refreshes and remember me cookies

### Advanced Features

[](#advanced-features)

- 🔒 **Suspicious Activity Detection** - Automatically detects multiple failed logins, rapid location changes, and unusual login times
- 📊 **Statistics &amp; Insights** - Get comprehensive login statistics including total logins, failed attempts, unique devices, and more
- 🔐 **Session Management** - View active sessions, revoke specific sessions, or logout all other devices
- 🛡️ **Device Trust Management** - Mark devices as trusted, manage device names, and require trusted devices for sensitive actions
- ⚡ **Rate Limiting** - Prevents notification spam with configurable rate limits
- 🔔 **Webhook Support** - Send webhooks to external services for authentication events
- 📤 **Export Functionality** - Export authentication logs to CSV or JSON format
- 🎯 **Query Scopes** - Powerful query scopes for filtering logs (successful, failed, suspicious, recent, by IP, by device, etc.)
- 🚦 **Middleware** - Protect routes with trusted device middleware

Documentation, Installation, and Usage Instructions
---------------------------------------------------

[](#documentation-installation-and-usage-instructions)

See the [documentation](https://rappasoft.com/docs/laravel-authentication-log) for detailed installation and usage instructions.

Version Compatibility
---------------------

[](#version-compatibility)

LaravelAuthentication LogFeatures8.x1.xBasic logging only9.x2.xBasic logging only10.x3.xBasic logging only11.x5.x, 6.xAll features (device fingerprinting, suspicious activity, webhooks, session management, etc.)12.x5.x, 6.xAll features (device fingerprinting, suspicious activity, webhooks, session management, etc.)13.x6.1+All features (device fingerprinting, suspicious activity, webhooks, session management, etc.)**Note:** Version 6.1+ requires Laravel 11.x, 12.x, or 13.x and PHP 8.2+. Version 5.x also supports Laravel 11.x and 12.x. For Laravel 10.x support, please use version 3.x.

Installation
------------

[](#installation)

```
composer require rappasoft/laravel-authentication-log
```

Quick Start
-----------

[](#quick-start)

### 1. Add the Trait to Your User Model

[](#1-add-the-trait-to-your-user-model)

```
use Rappasoft\LaravelAuthenticationLog\Traits\AuthenticationLoggable;

class User extends Authenticatable
{
    use AuthenticationLoggable;
}
```

### 2. Publish and Run Migrations

[](#2-publish-and-run-migrations)

**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:**

- Laravel 10.x support was dropped (v6.1+ supports Laravel 11.x, 12.x, and 13.x)
- PHP 8.1+ was required (PHP 8.2+ as of v6.1.0)
- See the [Upgrade Guide](docs/start/upgrade.md) for detailed migration instructions

### 3. Configure (Optional)

[](#3-configure-optional)

```
php artisan vendor:publish --provider="Rappasoft\LaravelAuthenticationLog\LaravelAuthenticationLogServiceProvider" --tag="authentication-log-config"
```

Usage Examples
--------------

[](#usage-examples)

### Get User Statistics

[](#get-user-statistics)

```
$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();
```

### Session Management

[](#session-management)

```
// 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();
```

### Device Management

[](#device-management)

```
// 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
}
```

### Query Scopes

[](#query-scopes)

```
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();
```

### Suspicious Activity Detection

[](#suspicious-activity-detection)

```
// 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'
//     ]
// ]
```

### Middleware for Trusted Devices

[](#middleware-for-trusted-devices)

```
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 Logs

[](#export-logs)

```
# 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
```

### Webhook Configuration

[](#webhook-configuration)

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',
        ],
    ],
],
```

Configuration
-------------

[](#configuration)

The package includes comprehensive configuration options:

- **Notifications** - Configure new device and failed login notifications with rate limiting
- **Suspicious Activity** - Configure thresholds and detection rules
- **Webhooks** - Set up webhook endpoints for external integrations
- **Database** - Customize table name and database connection
- **Session Restoration** - Configure session restoration prevention (prevents duplicate log entries)
- **New User Threshold** - Configure time window for new user detection

See the [configuration documentation](https://rappasoft.com/docs/laravel-authentication-log/start/configuration) for all available options.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Anthony Rappa](https://github.com/rappasoft)
- [yadahan/laravel-authentication-log](https://github.com/yadahan/laravel-authentication-log)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance95

Actively maintained with recent releases

Popularity65

Solid adoption and visibility

Community41

Growing community involvement

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 72.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~142 days

Recently: every ~200 days

Total

13

Last Release

24d ago

Major Versions

v1.3.0 → v2.0.02022-02-19

v2.0.0 → v3.0.02023-02-23

v3.0.0 → v4.0.02024-03-30

v4.0.0 → v5.0.02025-03-25

v5.0.0 → v6.0.02025-12-05

PHP version history (4 changes)v1.0.0PHP ^8.0

v1.2.0PHP ^7.4|^8.0

v3.0.0PHP ^8.1

v6.1.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7391f7cc3ee64ecd12d948708b2c3d901d2baa20f34a16523b9d7f2e167abb5b?d=identicon)[rappa819](/maintainers/rappa819)

---

Top Contributors

[![rappasoft](https://avatars.githubusercontent.com/u/6026504?v=4)](https://github.com/rappasoft "rappasoft (122 commits)")[![lrljoe](https://avatars.githubusercontent.com/u/104938042?v=4)](https://github.com/lrljoe "lrljoe (9 commits)")[![forxer](https://avatars.githubusercontent.com/u/407917?v=4)](https://github.com/forxer "forxer (7 commits)")[![t0nka](https://avatars.githubusercontent.com/u/4823546?v=4)](https://github.com/t0nka "t0nka (5 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (5 commits)")[![publiux](https://avatars.githubusercontent.com/u/2847188?v=4)](https://github.com/publiux "publiux (3 commits)")[![tungtm-unica](https://avatars.githubusercontent.com/u/101539988?v=4)](https://github.com/tungtm-unica "tungtm-unica (2 commits)")[![JustinByrne](https://avatars.githubusercontent.com/u/14056930?v=4)](https://github.com/JustinByrne "JustinByrne (2 commits)")[![MathieuMaas](https://avatars.githubusercontent.com/u/34303750?v=4)](https://github.com/MathieuMaas "MathieuMaas (2 commits)")[![mstralka](https://avatars.githubusercontent.com/u/439680?v=4)](https://github.com/mstralka "mstralka (2 commits)")[![tommica](https://avatars.githubusercontent.com/u/1391027?v=4)](https://github.com/tommica "tommica (1 commits)")[![aliowacom](https://avatars.githubusercontent.com/u/91871615?v=4)](https://github.com/aliowacom "aliowacom (1 commits)")[![nessimabadi](https://avatars.githubusercontent.com/u/11637110?v=4)](https://github.com/nessimabadi "nessimabadi (1 commits)")[![localpath](https://avatars.githubusercontent.com/u/44937070?v=4)](https://github.com/localpath "localpath (1 commits)")[![jwpage](https://avatars.githubusercontent.com/u/52687?v=4)](https://github.com/jwpage "jwpage (1 commits)")[![roberto4for](https://avatars.githubusercontent.com/u/205741732?v=4)](https://github.com/roberto4for "roberto4for (1 commits)")[![SkyLundy](https://avatars.githubusercontent.com/u/61801600?v=4)](https://github.com/SkyLundy "SkyLundy (1 commits)")[![dev-mazur](https://avatars.githubusercontent.com/u/80200036?v=4)](https://github.com/dev-mazur "dev-mazur (1 commits)")[![logan-jobzmall](https://avatars.githubusercontent.com/u/31047862?v=4)](https://github.com/logan-jobzmall "logan-jobzmall (1 commits)")[![lucassmacedo](https://avatars.githubusercontent.com/u/3357243?v=4)](https://github.com/lucassmacedo "lucassmacedo (1 commits)")

---

Tags

laravelrappasoftlaravel-authentication-log

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rappasoft-laravel-authentication-log/health.svg)

```
[![Health](https://phpackages.com/badges/rappasoft-laravel-authentication-log/health.svg)](https://phpackages.com/packages/rappasoft-laravel-authentication-log)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213421.0k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
