schneespur/release/schneespur-1.0.2/app/Services/OwntracksCredentialService.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

40 lines
1 KiB
PHP

<?php
namespace App\Services;
use App\Models\OwntracksCredentialEvent;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class OwntracksCredentialService
{
/**
* @return array{username: string, password: string}
*/
public function generateCredentials(User $driver, User $actor): array
{
$isRotation = $driver->owntracks_username !== null;
if (! $isRotation) {
$driver->owntracks_username = 'driver-' . $driver->id . '-' . Str::lower(Str::random(4));
}
$plaintext = Str::random(16);
$driver->owntracks_password_hash = Hash::make($plaintext);
$driver->owntracks_password_revealed_at = null;
$driver->save();
OwntracksCredentialEvent::create([
'driver_id' => $driver->id,
'event' => $isRotation ? 'rotated' : 'created',
'actor_user_id' => $actor->id,
]);
return [
'username' => $driver->owntracks_username,
'password' => $plaintext,
];
}
}