Files
f3-simple-blog/scripts/create-admin.php
2026-03-30 00:00:03 +02:00

31 lines
724 B
PHP

<?php
declare(strict_types=1);
$f3 = require __DIR__ . '/bootstrap.php';
User::bootstrap($f3->get('DB'));
$username = trim((string) ($argv[1] ?? ''));
if ($username === '') {
fwrite(STDERR, "Usage: php scripts/create-admin.php <username>\n");
exit(1);
}
fwrite(STDOUT, 'Mot de passe (10 caractères minimum): ');
if (stripos(PHP_OS, 'WIN') !== 0) {
system('stty -echo');
}
$password = trim((string) fgets(STDIN));
if (stripos(PHP_OS, 'WIN') !== 0) {
system('stty echo');
}
fwrite(STDOUT, PHP_EOL);
try {
$id = (new User())->create($username, $password);
fwrite(STDOUT, "Admin créé (ID {$id}).\n");
} catch (RuntimeException $e) {
fwrite(STDERR, $e->getMessage() . PHP_EOL);
exit(1);
}