diff --git a/lib/panel.js b/lib/panel.js
index 1d17591..cf27532 100644
--- a/lib/panel.js
+++ b/lib/panel.js
@@ -383,6 +383,13 @@ const gift = (account, body) => {
const MAX_QUEST_LEVEL = 100;
+// a password for a player who lost theirs: read out or pasted to them, so
+// nothing that looks like something else (0 O, 1 l I).
+const TEMP_PASSWORD_LETTERS = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789";
+const TEMP_PASSWORD_LENGTH = 12;
+const randomPassword = () => Array.from({length: TEMP_PASSWORD_LENGTH},
+ () => TEMP_PASSWORD_LETTERS[crypto.randomInt(TEMP_PASSWORD_LETTERS.length)]).join("");
+
const wholeNumber = (value, min, max) => (Number.isInteger(value) && value >= min && value <= max ? value : null);
// returns {ok: text} or {error: text}.
@@ -537,6 +544,27 @@ const act = (account, body) => {
}
// guide: lets the player log in as one (lib/accounts.js setLoginChoices).
// it shows from their next login.
+ // lost access: a new random password, shown here once. it signs them out
+ // everywhere (lib/accounts.js setPassword); with `twoStepOff` their 2FA
+ // goes as well, for a lost authenticator.
+ case "tempPassword": {
+ let password = randomPassword();
+ // the account rules want a capital, a small letter and a digit, and no
+ // common word or the username in it: draw again until it has them.
+ while (accounts.setPassword(account, password)) {
+ password = randomPassword();
+ }
+ const twoStepOff = body.twoStepOff === true && totp.isOn(account);
+ if (twoStepOff) {
+ totp.turnOff(account);
+ }
+ accounts.save(account);
+ world.disconnect(account);
+ manage.forget(account);
+ modpanel.forget(account);
+ modlog.record("admin", "temporary password set", account.username, twoStepOff ? "2FA turned off" : "");
+ return {ok: `${name}'s password is now ${password}${twoStepOff ? " and their 2FA is off" : ""}. Ask them to change it on their account page.`, password};
+ }
case "guide": {
const on = body.on === true;
account.guideGiven = on;
diff --git a/public/admin.html b/public/admin.html
index 69992ef..5a7d10b 100644
--- a/public/admin.html
+++ b/public/admin.html
@@ -502,6 +502,15 @@
+
+
Lost access
+
A new random password, shown once. They are signed out everywhere and should change it on their account page.
+
+
+
+
+
+
Adventure level
@@ -1529,6 +1538,7 @@
label.append(box, ` ${badge.label}`);
return label;
}));
+ $("temp-two-step-off").disabled = !current || !current.twoStep;
$("guide-toggle").textContent = current && current.guide ? "Remove guide" : "Make guide";
$("discord-name").textContent = current && current.discord ? `Discord: ${current.discord}` : "No Discord linked";
$("admin-dashboard-access").textContent = current && current.adminDashboardAccess ? "Remove Discord dashboard access" : "Allow Discord dashboard access";
@@ -1566,7 +1576,8 @@
selected = username;
current = null;
setStatus($("detail-status"), "");
- for (const id of ["new-name", "ban-hours", "silence-hours", "message-text", "gems-amount", "gift-value", "gift-text"]) {
+ $("temp-password-row").hidden = true;
+ for (const id of ["temp-password", "new-name", "ban-hours", "silence-hours", "message-text", "gems-amount", "gift-value", "gift-text"]) {
$(id).value = "";
}
hashArg = username;
@@ -1720,6 +1731,7 @@
case "permissions": return permissionChoices();
case "adminDashboardAccess": return {on: !(current || {}).adminDashboardAccess};
case "guide": return {on: !(current || {}).guide};
+ case "tempPassword": return {twoStepOff: $("temp-two-step-off").checked};
case "message": return {text: $("message-text").value};
case "gems": return {amount: numberFrom("gems-amount")};
case "gift": return giftBody();
@@ -1731,6 +1743,10 @@
}
};
+ $("temp-password-copy").addEventListener("click", () => {
+ navigator.clipboard.writeText($("temp-password").value).catch(() => $("temp-password").select());
+ });
+
// the "N ago" buttons fill the last-seen box and press Set.
$("detail").addEventListener("click", event => {
const quick = event.target.closest("button[data-ago]");
@@ -1760,6 +1776,9 @@
if (action === "banDevices" && !window.confirm(`Hardware ban ${selected}? Everyone on their hardware is put out.`)) {
return;
}
+ if (action === "tempPassword" && !window.confirm(`Give ${selected} a new random password? Their old one stops working and they are signed out everywhere.`)) {
+ return;
+ }
button.disabled = true;
const result = await api("account", {username: selected, action, ...actionBody(action)});
button.disabled = false;
@@ -1767,6 +1786,11 @@
if (result.ok && action === "delete") {
selected = null;
}
+ if (result.ok && action === "tempPassword") {
+ $("temp-password").value = result.data.password;
+ $("temp-password-row").hidden = false;
+ $("temp-two-step-off").checked = false;
+ }
if (result.ok && action === "rename") {
selected = result.data.username;
$("new-name").value = "";