Available for select projects New York · Working worldwide
Rappasoft LLC
Menu

Laravel Authentication Log / Documentation / v6

Device Management

Installation, configuration, and usage guidance maintained with the project.

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

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.

How It Works

When a user logs in, the package automatically:

  1. Generates a device fingerprint using browser characteristics
  2. Creates a friendly device name (e.g., "Chrome on Windows")
  3. Checks if the device has been seen before
  4. Stores the device information with the authentication log

Generated names recognize Chrome, Firefox, Edge, Opera, and Safari, including their iOS user agents. Browser-specific tokens take precedence over shared engine tokens, and Android and iOS take precedence over Linux and Mac. Unrecognized browser and OS tokens use Unknown Browser and Unknown OS respectively; a missing user agent produces Unknown Browser on Unknown OS.

Device names are display labels. Improved name detection does not change existing device_id fingerprints, device trust, or new-device notifications. Existing stored names remain until a new log is created or you call updateDeviceName().

Getting User Devices

Get all devices that have been used by a user:

1$user = User::find(1);
2$devices = $user->getDevices();
3 
4// Returns a collection with:
5// - device_id
6// - device_name
7// - ip_address
8// - user_agent
9// - is_trusted
10// - login_at (most recent)

Trusting Devices

Mark a device as trusted to allow it access to sensitive actions:

1$user = User::find(1);
2$deviceId = 'abc123...'; // Device fingerprint
3 
4// Trust a device
5$user->trustDevice($deviceId);
6 
7// Check if device is trusted
8if ($user->isDeviceTrusted($deviceId)) {
9 // Device is trusted
10}

Untrusting Devices

Remove trust from a device:

1$user = User::find(1);
2$deviceId = 'abc123...';
3 
4$user->untrustDevice($deviceId);

Updating Device Names

Allow users to customize device names for easier identification:

1$user = User::find(1);
2$deviceId = 'abc123...';
3 
4$user->updateDeviceName($deviceId, 'My Work Laptop');

Example: Device Management UI

1// In your controller
2public function devices()
3{
4 $user = auth()->user();
5 $devices = $user->getDevices();
6 
7 return view('profile.devices', compact('devices'));
8}
9 
10// In your view
11@foreach($devices as $device)
12 <div class="device-item">
13 <div>
14 <strong>{{ $device->device_name }}</strong>
15 @if($device->is_trusted)
16 <span class="badge badge-success">Trusted</span>
17 @endif
18 </div>
19 <div>
20 Last used: {{ $device->login_at->diffForHumans() }}
21 </div>
22 <div>
23 <form action="{{ route('devices.trust', $device->device_id) }}" method="POST">
24 @csrf
25 @if($device->is_trusted)
26 <button type="submit" name="action" value="untrust">Untrust Device</button>
27 @else
28 <button type="submit" name="action" value="trust">Trust Device</button>
29 @endif
30 </form>
31 </div>
32 </div>
33@endforeach

Getting Current Device ID

To get the current device's fingerprint:

1use Rappasoft\LaravelAuthenticationLog\Helpers\DeviceFingerprint;
2 
3$currentDeviceId = DeviceFingerprint::generate(request());
4$deviceName = DeviceFingerprint::generateDeviceName(request());