36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
if (PHP_SAPI !== 'cli') {
|
|
http_response_code(404);
|
|
exit;
|
|
}
|
|
|
|
require dirname(__DIR__) . '/app/bootstrap.php';
|
|
|
|
use App\Database;
|
|
|
|
$username = trim((string) readline('관리자 아이디: '));
|
|
$displayName = trim((string) readline('표시 이름: '));
|
|
fwrite(STDOUT, '관리자 비밀번호: ');
|
|
if (function_exists('shell_exec')) shell_exec('stty -echo');
|
|
$password = trim((string) fgets(STDIN));
|
|
if (function_exists('shell_exec')) shell_exec('stty echo');
|
|
fwrite(STDOUT, PHP_EOL);
|
|
|
|
if ($username === '' || $displayName === '' || strlen($password) < 12) {
|
|
fwrite(STDERR, "아이디와 표시 이름, 12자 이상의 비밀번호가 필요합니다.\n");
|
|
exit(1);
|
|
}
|
|
|
|
$statement = Database::connection()->prepare(
|
|
'INSERT INTO admins (username, password_hash, display_name) VALUES (:username, :password_hash, :display_name)'
|
|
);
|
|
$statement->execute([
|
|
'username' => $username,
|
|
'password_hash' => password_hash($password, PASSWORD_DEFAULT),
|
|
'display_name' => $displayName,
|
|
]);
|
|
fwrite(STDOUT, "관리자 계정이 생성되었습니다.\n");
|