rappasoft/laravel-authentication-log
The package uses device fingerprinting to reliably identify and manage user devices. Each device is assigned a unique fingerprint based on browser characteristics, IP address, and other factors.
Device fingerprinting uses SHA-256 hashing to create a unique identifier for each device. This is more reliable than using just IP address and user agent, as it accounts for multiple factors.
When a user logs in, the package automatically:
Get all devices that have been used by a user:
$user = User::find(1);
$devices = $user->getDevices();
// Returns a collection with:
// - device_id
// - device_name
// - ip_address
// - user_agent
// - is_trusted
// - login_at (most recent)
Mark a device as trusted to allow it access to sensitive actions:
$user = User::find(1);
$deviceId = 'abc123...'; // Device fingerprint
// Trust a device
$user->trustDevice($deviceId);
// Check if device is trusted
if ($user->isDeviceTrusted($deviceId)) {
// Device is trusted
}
Remove trust from a device:
$user = User::find(1);
$deviceId = 'abc123...';
$user->untrustDevice($deviceId);
Allow users to customize device names for easier identification:
$user = User::find(1);
$deviceId = 'abc123...';
$user->updateDeviceName($deviceId, 'My Work Laptop');
// In your controller
public function devices()
{
$user = auth()->user();
$devices = $user->getDevices();
return view('profile.devices', compact('devices'));
}
// In your view
[@foreach](https://github.com/foreach)($devices as $device)
<div class="device-item">
<div>
<strong>{{ $device->device_name }}</strong>
[@if](https://github.com/if)($device->is_trusted)
<span class="badge badge-success">Trusted</span>
[@endif](https://github.com/endif)
</div>
<div>
Last used: {{ $device->login_at->diffForHumans() }}
</div>
<div>
<form action="{{ route('devices.trust', $device->device_id) }}" method="POST">
[@csrf](https://github.com/csrf)
[@if](https://github.com/if)($device->is_trusted)
<button type="submit" name="action" value="untrust">Untrust Device</button>
[@else](https://github.com/else)
<button type="submit" name="action" value="trust">Trust Device</button>
[@endif](https://github.com/endif)
</form>
</div>
</div>
[@endforeach](https://github.com/endforeach)
To get the current device's fingerprint:
use Rappasoft\LaravelAuthenticationLog\Helpers\DeviceFingerprint;
$currentDeviceId = DeviceFingerprint::generate(request());
$deviceName = DeviceFingerprint::generateDeviceName(request());
How can I help you explore Laravel packages today?