feat(admin): verify the backoffice password with PBKDF2, not plaintext compare

- ui/auth.js: derive PBKDF2-HMAC-SHA256(name:password) with a per-deploy salt
  (250k iterations) and compare against the verifier in constant time
- config/admin-credentials.json holds salt/iterations/verifier only — no password
- server/set-admin-password.mjs generates/rotates that file (CLI or hidden prompt)
- login is async now: button shows a pending state; config load errors surface in the form
- SW precaches the credentials file; version bumped to 2026.11.19.4
- docs: README/AGENTS explain rotation and the residual limits of a client-side gate
This commit is contained in:
Bkk1234 committed 2026-11-19 11:32:48 +07:00
1 parent cd5cb5dd08
commit a629e67ca4
8 files changed
+249 -32

No files matched your search

+22 -6
View File
@@ -97,7 +97,7 @@ export function adminView(ctx) {
root.querySelector("#login-name")?.focus({ preventScroll: true });
form.addEventListener("submit", (event) => {
form.addEventListener("submit", async (event) => {
event.preventDefault();
errorEl.textContent = "";
[nameEl, passEl].forEach((field) => field.closest(".field").classList.remove("field--error"));
@@ -106,17 +106,33 @@ export function adminView(ctx) {
(nameEl.value.trim() ? passEl : nameEl).focus();
return;
}
const labelEl = submitEl.querySelector("span");
const originalLabel = labelEl ? labelEl.textContent : "";
submitEl.disabled = true;
const result = login(nameEl.value, passEl.value);
submitEl.disabled = false;
if (labelEl) labelEl.textContent = "กำลังตรวจสอบ…";
let result;
try {
result = await login(nameEl.value, passEl.value);
} catch (error) {
result = { ok: false, error: `ตรวจรหัสไม่สำเร็จ: ${error.message}` };
} finally {
submitEl.disabled = false;
if (labelEl) labelEl.textContent = originalLabel;
}
if (result.ok) {
mount(root);
toast("เข้าสู่หน้าจัดการแล้ว");
return;
}
const message = result.locked
? `ลองผิดหลายครั้งเกินไป — รออีก ${result.retryIn} วินาที`
: `ชื่อหรือรหัสไม่ถูกต้อง (ลองได้อีก ${result.remaining} ครั้ง)`;
const message =
result.error ||
(result.locked
? `ลองผิดหลายครั้งเกินไป — รออีก ${result.retryIn} วินาที`
: `ชื่อหรือรหัสไม่ถูกต้อง (ลองได้อีก ${result.remaining} ครั้ง)`);
errorEl.textContent = message;
passEl.value = "";
[nameEl, passEl].forEach((field) => field.closest(".field").classList.add("field--error"));