05/02/2026 updated code for security 3
This commit is contained in:
@@ -237,6 +237,14 @@ async function handleLogin() {
|
||||
_pending_enc_key_salt: data.enc_key_salt,
|
||||
});
|
||||
handleMfaStage(password);
|
||||
// Reset MFA view to TOTP mode each time it's shown
|
||||
$("mfa-totp-section").classList.remove("hidden");
|
||||
$("mfa-backup-section").classList.add("hidden");
|
||||
$("btn-mfa-use-backup").classList.remove("hidden");
|
||||
$("btn-mfa-use-totp").classList.add("hidden");
|
||||
$("mfa-hint").textContent = "Enter your 6-digit authenticator code.";
|
||||
$("mfa-code").value = "";
|
||||
$("mfa-backup-code").value = "";
|
||||
showView("mfa");
|
||||
$("mfa-code").focus();
|
||||
return;
|
||||
@@ -252,18 +260,35 @@ async function handleLogin() {
|
||||
|
||||
function handleMfaStage(password) {
|
||||
$("btn-mfa-verify").onclick = async () => {
|
||||
const code = $("mfa-code").value.trim();
|
||||
hideError("mfa-error");
|
||||
if (code.length !== 6) {
|
||||
showError("mfa-error", "Enter the 6-digit code.");
|
||||
return;
|
||||
const usingBackup = !$("mfa-backup-section").classList.contains("hidden");
|
||||
const body = { mfa_token: _mfaToken };
|
||||
|
||||
if (usingBackup) {
|
||||
const code = $("mfa-backup-code")
|
||||
.value.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[\s-]/g, "");
|
||||
if (!code) {
|
||||
showError("mfa-error", "Enter your backup code.");
|
||||
return;
|
||||
}
|
||||
body.backup_code = code;
|
||||
} else {
|
||||
const code = $("mfa-code").value.trim();
|
||||
if (code.length !== 6) {
|
||||
showError("mfa-error", "Enter the 6-digit code.");
|
||||
return;
|
||||
}
|
||||
body.totp_code = code;
|
||||
}
|
||||
|
||||
$("btn-mfa-verify").disabled = true;
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/api/auth/mfa/verify`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ mfa_token: _mfaToken, totp_code: code }),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
@@ -284,6 +309,24 @@ function handleMfaStage(password) {
|
||||
$("btn-mfa-verify").disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
$("btn-mfa-use-backup").onclick = () => {
|
||||
$("mfa-totp-section").classList.add("hidden");
|
||||
$("mfa-backup-section").classList.remove("hidden");
|
||||
$("btn-mfa-use-backup").classList.add("hidden");
|
||||
$("btn-mfa-use-totp").classList.remove("hidden");
|
||||
$("mfa-hint").textContent = "Enter one of your saved backup codes.";
|
||||
$("mfa-backup-code").focus();
|
||||
};
|
||||
|
||||
$("btn-mfa-use-totp").onclick = () => {
|
||||
$("mfa-backup-section").classList.add("hidden");
|
||||
$("mfa-totp-section").classList.remove("hidden");
|
||||
$("btn-mfa-use-totp").classList.add("hidden");
|
||||
$("btn-mfa-use-backup").classList.remove("hidden");
|
||||
$("mfa-hint").textContent = "Enter your 6-digit authenticator code.";
|
||||
$("mfa-code").focus();
|
||||
};
|
||||
}
|
||||
|
||||
async function completeLogin(data, masterPassword) {
|
||||
|
||||
Reference in New Issue
Block a user