Files
nexus/wiki/concepts/totp.md

63 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# TOTP (Time-based One-Time Password)
## Aliases
- TOTP
- Time-based One-Time Password
- 动态口令
- 一次性密码
## Type
Concept / Security Protocol
## Description
TOTP 是一种基于时间的一次性密码算法通过共享密钥和当前时间戳生成动态验证码广泛用于双因素认证2FA
## How It Works
```
1. 服务端与客户端共享一个 Secret Key密钥
2. 双方使用相同的算法:
TOTP = HMAC-SHA1(Secret Key, floor(Unix_Time / 30))
3. 每 30 秒生成一个新的 6 位数字验证码
4. 用户在登录时输入该验证码完成身份验证
```
## Key Characteristics
| 特性 | 说明 |
|------|------|
| 时效性 | 每 30 秒更新一次 |
| 长度 | 通常 6 位数字 |
| 离线可用 | 不需要网络连接(和时间同步) |
| 算法标准 | RFC 6238 |
| 变体 | HOTP基于计数器、TOTP基于时间 |
## TOTP in Password Managers
### Bitwarden (Official)
- TOTP 功能需要**付费会员**
- 自动填充验证码
- 支持大多数网站的双因素认证
### NodeWarden
- 通过 `TOTP_SECRET` 环境变量**免费**提供
- 配置后可在 Bitwarden 客户端自动获取验证码
## Setting Up TOTP Secret
在 NodeWarden 中设置 TOTP
1. 在 Two-Factor Auth 页面获取 TOTP SecretBase32 编码字符串)
2. 将 Secret 填入 `TOTP_SECRET` 环境变量
3. 在 Bitwarden 客户端添加 TOTP大多数网站在设置 2FA 时会显示密钥
4. 在 Bitwarden 客户端设置 → 高级 → 身份验证器 TOTP 中填入密钥
## Related Concepts
- [[Multi-factor-Authentication]] — TOTP 是 MFA 的一种因素
- [[Passkey]] — 基于 WebAuthn 的无密码认证,比 TOTP 更安全
- [[Self-Hosted Password Manager]] — 自托管密码管理器通常内置 TOTP 支持
## Source
- [[nodewarden-把-bitwarden-搬上-cloudflare-workers-彻底告别服务器]]