feat: GTSIT 사이트 구축
This commit is contained in:
35
bin/create-admin.php
Normal file
35
bin/create-admin.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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");
|
||||
Reference in New Issue
Block a user