| 1 |
<?php |
| 2 |
/** |
| 3 |
* Standalone password-hash generator. |
| 4 |
* |
| 5 |
* Enter a new admin password below and this page prints the bcrypt hash. Copy |
| 6 |
* the hash and paste it into config.php as the value of ADMIN_PASS_HASH. |
| 7 |
* |
| 8 |
* This file has no dependencies and touches no database. Delete it (or keep it |
| 9 |
* out of production) once you have set your password. |
| 10 |
*/ |
| 11 |
|
| 12 |
$hash = ''; |
| 13 |
$password = ''; |
| 14 |
|
| 15 |
if ($_SERVER['REQUEST_METHOD'] === 'POST') { |
| 16 |
$password = (string) ($_POST['password'] ?? ''); |
| 17 |
if ($password !== '') { |
| 18 |
$hash = password_hash($password, PASSWORD_DEFAULT); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
function h($v): string |
| 23 |
{ |
| 24 |
return htmlspecialchars((string) $v, ENT_QUOTES, 'UTF-8'); |
| 25 |
} |
| 26 |
?><!doctype html> |
| 27 |
<html lang="en"> |
| 28 |
<head> |
| 29 |
<meta charset="utf-8"> |
| 30 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 31 |
<title>Generate password hash</title> |
| 32 |
<style> |
| 33 |
:root { color-scheme: light dark; } |
| 34 |
body { |
| 35 |
margin: 0; |
| 36 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; |
| 37 |
line-height: 1.5; |
| 38 |
background: #fff; |
| 39 |
color: #1f2328; |
| 40 |
padding: 32px 16px; |
| 41 |
} |
| 42 |
.box { max-width: 640px; margin: 0 auto; } |
| 43 |
h1 { font-size: 1.4rem; } |
| 44 |
p.muted { color: #656d76; font-size: 0.9rem; } |
| 45 |
label { display: block; margin: 16px 0 4px; font-weight: 600; } |
| 46 |
input[type=text] { |
| 47 |
width: 100%; |
| 48 |
padding: 10px 12px; |
| 49 |
font-size: 1rem; |
| 50 |
border: 1px solid #d0d7de; |
| 51 |
border-radius: 6px; |
| 52 |
font-family: inherit; |
| 53 |
background: #fff; |
| 54 |
color: #1f2328; |
| 55 |
} |
| 56 |
button { |
| 57 |
margin-top: 16px; |
| 58 |
padding: 10px 18px; |
| 59 |
font-size: 0.95rem; |
| 60 |
border: 1px solid #0969da; |
| 61 |
border-radius: 6px; |
| 62 |
background: #0969da; |
| 63 |
color: #fff; |
| 64 |
cursor: pointer; |
| 65 |
} |
| 66 |
.result { |
| 67 |
margin-top: 24px; |
| 68 |
padding: 16px; |
| 69 |
border: 1px solid #d0d7de; |
| 70 |
border-radius: 8px; |
| 71 |
background: #f6f8fa; |
| 72 |
} |
| 73 |
.result code, textarea.hash { |
| 74 |
display: block; |
| 75 |
width: 100%; |
| 76 |
box-sizing: border-box; |
| 77 |
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; |
| 78 |
font-size: 0.9rem; |
| 79 |
word-break: break-all; |
| 80 |
} |
| 81 |
textarea.hash { |
| 82 |
margin-top: 8px; |
| 83 |
padding: 10px 12px; |
| 84 |
border: 1px solid #d0d7de; |
| 85 |
border-radius: 6px; |
| 86 |
resize: vertical; |
| 87 |
background: #fff; |
| 88 |
color: #1f2328; |
| 89 |
} |
| 90 |
pre.snippet { |
| 91 |
margin-top: 12px; |
| 92 |
padding: 12px; |
| 93 |
background: #eaeef2; |
| 94 |
border-radius: 6px; |
| 95 |
overflow-x: auto; |
| 96 |
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; |
| 97 |
font-size: 0.85rem; |
| 98 |
} |
| 99 |
@media (prefers-color-scheme: dark) { |
| 100 |
body { background: #0d1117; color: #e6edf3; } |
| 101 |
input[type=text], textarea.hash { background: #0d1117; color: #e6edf3; border-color: #30363d; } |
| 102 |
.result { background: #161b22; border-color: #30363d; } |
| 103 |
pre.snippet { background: #161b22; } |
| 104 |
p.muted { color: #8b949e; } |
| 105 |
} |
| 106 |
</style> |
| 107 |
</head> |
| 108 |
<body> |
| 109 |
<div class="box"> |
| 110 |
<h1>Generate an admin password hash</h1> |
| 111 |
<p class="muted"> |
| 112 |
Type a new password and submit. Copy the generated bcrypt hash into |
| 113 |
<code>config.php</code> as the value of <code>ADMIN_PASS_HASH</code>. |
| 114 |
The password itself is never stored. |
| 115 |
</p> |
| 116 |
|
| 117 |
<form method="post" autocomplete="off"> |
| 118 |
<label for="password">New password</label> |
| 119 |
<input type="text" id="password" name="password" value="<?= h($password) ?>" |
| 120 |
placeholder="Enter the new password" required autofocus> |
| 121 |
<button type="submit">Generate hash</button> |
| 122 |
</form> |
| 123 |
|
| 124 |
<?php if ($hash !== ''): ?> |
| 125 |
<div class="result"> |
| 126 |
<strong>Your hash:</strong> |
| 127 |
<textarea class="hash" rows="2" readonly onclick="this.select()"><?= h($hash) ?></textarea> |
| 128 |
<p class="muted">Paste it into config.php, replacing the current value:</p> |
| 129 |
<pre class="snippet">define('ADMIN_PASS_HASH', '<?= h($hash) ?>');</pre> |
| 130 |
<p class="muted"> |
| 131 |
Verification check: <?= password_verify($password, $hash) ? '✓ hash matches the password' : '✗ mismatch' ?> |
| 132 |
</p> |
| 133 |
</div> |
| 134 |
<?php elseif ($_SERVER['REQUEST_METHOD'] === 'POST'): ?> |
| 135 |
<div class="result"><p class="muted">Please enter a non-empty password.</p></div> |
| 136 |
<?php endif; ?> |
| 137 |
|
| 138 |
<p class="muted" style="margin-top:24px;"> |
| 139 |
Security note: delete this file (or block access to it) when you are done — |
| 140 |
it lets anyone who can reach it generate hashes. |
| 141 |
</p> |
| 142 |
</div> |
| 143 |
</body> |
| 144 |
</html> |
| 145 |
|