feat(webui): add optional TOTP 2FA for operator login (#351)
WebUI access was a single shared password. This adds optional
Authenticator TOTP as a second factor, with one-time recovery codes
and SSH as the last-resort disable path.
Login stays two HTTP posts with no pending token: a correct password
and enabled 2FA without a second factor returns { needsTotp: true };
the client then resubmits { password, totp } or { password, recoveryCode }.
The TOTP secret is wrapped with a password-derived AES-256-GCM key.
Eight XXXX-XXXX recovery codes are stored as SHA-256 hashes and each
code is consumed once. Enabling or disabling 2FA invalidates other
sessions; disabling still requires password plus TOTP or a recovery
code. SNOWLUMA_DEV_MODE hides the feature.
The login page uses a dedicated second-factor screen (Interior OTP
cells for the 6-digit code; the same cell UI for recovery codes,
grouped as XXXX-XXXX). Settings expose enroll/confirm/disable and
one-time recovery-code display.
Fixes #351
This commit is contained in:
23 files changed
+2676
-153
No files matched your search
@@ -37,6 +37,7 @@ import { useActionFeedback } from '@/contexts/ActionFeedbackContext';
|
||||
import { useSession } from '@/contexts/SessionContext';
|
||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
||||
import { TotpPanel } from '@/components/settings/totp-panel';
|
||||
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { SkeletonSwap } from '@/components/interior/skeleton-swap';
|
||||
@@ -1220,44 +1221,47 @@ function AccountPanel() {
|
||||
const [confirmLogout, setConfirmLogout] = useState(false);
|
||||
|
||||
return (
|
||||
<Group title="账号安全" icon={ShieldCheck} description="WebUI 仅有 admin 一个账号,密码以 scrypt 哈希持久化到 config/webui.json。">
|
||||
<SettingRow
|
||||
label="访问密码"
|
||||
hint={pwdSavedAt
|
||||
? <span className="text-success">已更新({new Date(pwdSavedAt).toLocaleTimeString()})— 其他设备的会话已失效。</span>
|
||||
: '修改后其他设备的会话将立即失效。'}
|
||||
>
|
||||
<Button variant="outline" size="sm" onClick={() => setShowChangePwd(true)}>
|
||||
<KeyRound className="size-4" /> 修改密码
|
||||
</Button>
|
||||
</SettingRow>
|
||||
<SettingRow label="退出登录" hint="立即清除当前浏览器的会话令牌。">
|
||||
<Button variant="ghost" size="sm" onClick={() => setConfirmLogout(true)} className="text-destructive hover:text-destructive">
|
||||
<div className="flex flex-col gap-5">
|
||||
<Group title="账号安全" icon={ShieldCheck} description="WebUI 仅有 admin 一个账号,密码以 scrypt 哈希持久化到 config/webui.json。">
|
||||
<SettingRow
|
||||
label="访问密码"
|
||||
hint={pwdSavedAt
|
||||
? <span className="text-success">已更新({new Date(pwdSavedAt).toLocaleTimeString()})— 其他设备的会话已失效。</span>
|
||||
: '修改后其他设备的会话将立即失效。'}
|
||||
>
|
||||
<Button variant="outline" size="sm" onClick={() => setShowChangePwd(true)}>
|
||||
<KeyRound className="size-4" /> 修改密码
|
||||
</Button>
|
||||
</SettingRow>
|
||||
<SettingRow label="退出登录" hint="立即清除当前浏览器的会话令牌。">
|
||||
<Button variant="ghost" size="sm" onClick={() => setConfirmLogout(true)} className="text-destructive hover:text-destructive">
|
||||
退出登录
|
||||
</Button>
|
||||
</SettingRow>
|
||||
</Button>
|
||||
</SettingRow>
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmLogout}
|
||||
onOpenChange={setConfirmLogout}
|
||||
title="确认退出登录?"
|
||||
description="退出后将清除当前会话令牌,需要重新输入访问密码才能进入控制台。"
|
||||
confirmText="退出登录"
|
||||
destructive
|
||||
activity={{
|
||||
title: '正在退出登录',
|
||||
successTitle: '已退出登录',
|
||||
errorTitle: '退出登录失败',
|
||||
}}
|
||||
onConfirm={onLogout}
|
||||
/>
|
||||
<ConfirmDialog
|
||||
open={confirmLogout}
|
||||
onOpenChange={setConfirmLogout}
|
||||
title="确认退出登录?"
|
||||
description="退出后将清除当前会话令牌,需要重新输入访问密码才能进入控制台。"
|
||||
confirmText="退出登录"
|
||||
destructive
|
||||
activity={{
|
||||
title: '正在退出登录',
|
||||
successTitle: '已退出登录',
|
||||
errorTitle: '退出登录失败',
|
||||
}}
|
||||
onConfirm={onLogout}
|
||||
/>
|
||||
|
||||
<ChangePasswordDialog
|
||||
open={showChangePwd}
|
||||
onOpenChange={setShowChangePwd}
|
||||
onSuccess={() => setPwdSavedAt(Date.now())}
|
||||
/>
|
||||
</Group>
|
||||
<ChangePasswordDialog
|
||||
open={showChangePwd}
|
||||
onOpenChange={setShowChangePwd}
|
||||
onSuccess={() => setPwdSavedAt(Date.now())}
|
||||
/>
|
||||
</Group>
|
||||
<TotpPanel />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user