harryes/laravel-sentinellog
All-in-one Laravel security and auth logging package: tracks login/logout/failed attempts with device + geo detection, alerts, TOTP 2FA, session management, brute-force protection, geo-fencing, SSO, and new-location verify/deny flows.
Installation:
composer require harryes/laravel-sentinellog
php artisan vendor:publish --provider="Harryes\SentinelLog\SentinelLogServiceProvider" --tag="migrations"
php artisan migrate
Publish the config file:
php artisan vendor:publish --provider="Harryes\SentinelLog\SentinelLogServiceProvider" --tag="config"
Configuration:
Edit config/sentinel-log.php to enable/disable features (e.g., geo_fencing, brute_force_protection). Set default values for:
'max_failed_attempts' => 5,
'lockout_duration' => 15, // minutes
'allowed_countries' => ['US', 'GB'], // ISO country codes
First Use Case:
Enable logging in AuthServiceProvider:
use Harryes\SentinelLog\Facades\SentinelLog;
public function boot()
{
SentinelLog::enable();
}
Test by attempting a login (successful or failed). Check the sentinel_logs table for entries.
Authentication Logging:
SentinelLogMiddleware if custom logic is needed.
// app/Http/Middleware/Authenticate.php
public function handle($request, Closure $next)
{
SentinelLog::logLogin($request->user());
return $next($request);
}
SentinelLog::logFailedAttempt($request, $credentials).Device & Geolocation Tracking:
SentinelLog::trackDevice($request) in middleware to capture:
geoip-database/geoip).public function handle($request, Closure $next)
{
SentinelLog::trackDevice($request);
return $next($request);
}
2FA Integration:
'2fa' => true.SentinelLog::verify2FA($user) to trigger TOTP verification.use Harryes\SentinelLog\Facades\SentinelLog;
$qrCode = SentinelLog::generate2FAQR($user);
Session Management:
if (!SentinelLog::isTrustedSession($request)) {
auth()->logout();
return redirect()->route('login')->with('error', 'Session hijacked!');
}
Brute Force Protection:
max_failed_attempts and lockout_duration.if (SentinelLog::isIPLocked($request->ip())) {
return back()->with('error', 'Too many attempts. Try again later.');
}
Geo-Fencing:
if (!SentinelLog::isAllowedCountry($request->ip())) {
return back()->with('error', 'Login restricted in your region.');
}
SSO Support:
$token = SentinelLog::generateSSOToken($user);
SentinelLog::validateSSOToken($token);
New Location Verification:
'new_location_verification' => true.Notifications:
php artisan vendor:publish --provider="Harryes\SentinelLog\SentinelLogServiceProvider" --tag="views"
Harryes\SentinelLog\Events\LoginEvent to trigger custom logic.APIs:
SentinelLog::getUserLogs($user) to fetch activity in APIs:
return response()->json(SentinelLog::getUserLogs(auth()->user()));
Admin Dashboard:
$failedAttempts = SentinelLog::failedAttempts()->latest()->take(10)->get();
Testing:
SentinelLog in tests:
$this->partialMock(SentinelLog::class, ['logLogin']);
GeoIP Database:
geoip-database/geoip package. Install separately:
composer require geoip-database/geoip
php artisan sentinellog:update-geoip
Rate Limiting:
config/rate-limiting.php is configured for high traffic:
'default' => [
'maxAttempts' => 100,
],
Session Hijacking:
isTrustedSession() compares stored device/location. False positives may occur with VPNs/proxies. Whitelist known IPs in config:
'trusted_ips' => ['192.168.1.1'],
2FA Setup:
$recoveryCodes = SentinelLog::generate2FARecoveryCodes($user);
Performance:
SentinelLog::disable() in non-critical routes:
SentinelLog::disable();
// Non-logged route
SentinelLog::enable();
Database Bloat:
// app/Console/Commands/CleanupSentinelLogs.php
public function handle()
{
SentinelLog::cleanupLogs(Carbon::now()->subDays(30));
}
Log Queries:
config/sentinel-log.php:
'debug' => true,
storage/logs/laravel.log for SQL queries.GeoIP Issues:
'geoip_database' => database_path('GeoLite2-Country.mmdb'),
Failed Logins:
failed events are logged in app/Providers/AuthServiceProvider.php:
public function boot()
{
$this->app['auth.failed'] = function ($request, $credentials) {
SentinelLog::logFailedAttempt($request, $credentials);
};
}
Notifications:
php artisan sentinellog:test-notification
Custom Log Fields:
sentinel_logs table by publishing migrations:
php artisan vendor:publish --provider="Harryes\SentinelLog\SentinelLogServiceProvider" --tag="migrations"
config/sentinel-log.php:
'custom_fields' => ['custom_field' => 'string'],
Custom Events:
Harryes\SentinelLog\Events\LoginEvent:
Event::listen(LoginEvent::class, function ($event) {
// Custom logic (e.g., Slack alert)
});
Override Views:
php artisan vendor:publish --provider="Harryes\SentinelLog\SentinelLogServiceProvider" --tag="views"
2fa-setup.blade.php or login-notification.blade.php.API Extensions:
Route::get('/api/user/logs', function () {
return SentinelLog::getUserLogs(auth()->user());
});
Conditional Logging:
Route::middleware(['web', 'sentinel-log:disable'])->group(function () {
// Routes where logging is disabled
});
How can I help you explore Laravel packages today?