Secure Coding & OWASP Top 10 for Backend · 课时

多因素身份验证与账户恢复

使用 MFA 将身份验证安全性提升到密码之上,并设计安全的账户恢复流程,避免恢复流程成为绕过保护措施的后门。

第 4 / 4 课13 个步骤

多因素身份验证与账户恢复 是 CoddyKit 上的免费 Secure Coding & OWASP Top 10 for Backend 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Secure Coding & OWASP Top 10 for Backend 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Secure Coding & OWASP Top 10 for Backend 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Beyond the Password

Strong access control and good session management still rest on one assumption: the user is who they claim. Passwords alone are weak. Multi-factor authentication adds layers so a stolen password is not enough.

The Three Factors

Authentication factors fall into categories:

  • Something you know — password, PIN
  • Something you have — phone, hardware key
  • Something you are — fingerprint, face

MFA combines two or more different categories.

TOTP Authenticator Apps

Time-based One-Time Passwords generate a 6-digit code from a shared secret and the current time. The server computes the same code to verify.

import pyotp
totp = pyotp.TOTP(user_secret)
is_valid = totp.verify(submitted_code)

Why SMS Is Weaker

SMS codes are better than nothing but vulnerable to SIM swapping and interception. Prefer TOTP apps or hardware keys; reserve SMS as a last-resort option.

Hardware Keys and WebAuthn

WebAuthn uses public-key cryptography with a hardware or platform authenticator. There is no shared secret to phish — the strongest widely available MFA.

Backup Codes

What if a user loses their phone? Issue one-time backup codes at enrollment. Store them hashed, just like passwords, and invalidate each after use.

stored = hash(backup_code)
# on use: verify then mark consumed

Recovery Is an Attack Surface

Account recovery often bypasses MFA. If recovery only needs an email link, an attacker who controls the inbox owns the account. Recovery must be as strong as login.

Secure Recovery Tokens

Recovery links should use a high-entropy, single-use, short-lived token, stored hashed and invalidated on use or password change.

token = secrets.token_urlsafe(32)
store(hash(token), expires_in=900)  # 15 minutes

Avoid Recovery Pitfalls

  • Do not reveal whether an email exists (enumeration)
  • Rate-limit recovery requests
  • Notify the user when recovery is initiated
  • Require re-enrollment of MFA after a full reset

Step-Up Authentication

For sensitive actions — changing email, large transfers — require a fresh factor even within an active session. This step-up limits the damage of a hijacked session.

Rate-Limiting the MFA Step

The MFA code entry is itself a target. A six-digit code has only a million possibilities, so without limits an attacker can brute-force it. Rate-limit and lock out after a few wrong codes, and expire each code quickly.

Quick Check

Test your MFA and recovery knowledge.

Recap

You strengthened authentication:

  • MFA combines factors from different categories
  • Prefer TOTP and WebAuthn over SMS
  • Provide hashed backup codes
  • Make recovery as strong as login with single-use, expiring tokens
  • Use step-up auth for sensitive actions
免费开始

用 AI 导师学习 Secure Coding & OWASP Top 10 for Backend — 免费

在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。

课程
12
课程
48

常见问题解答

「多因素身份验证与账户恢复」课时是免费的吗?

是的 — 「多因素身份验证与账户恢复」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Secure Coding & OWASP Top 10 for Backend 课程的其余内容,请升级到 CoddyKit PRO。 Secure Coding & OWASP Top 10 for Backend 课程共包含 4 节课。

「多因素身份验证与账户恢复」这节课中我会学到什么?

使用 MFA 将身份验证安全性提升到密码之上,并设计安全的账户恢复流程,避免恢复流程成为绕过保护措施的后门。 你通过在浏览器中直接运行的动手代码来练习 Secure Coding & OWASP Top 10 for Backend,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Secure Coding & OWASP Top 10 for Backend 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Secure Coding & OWASP Top 10 for Backend 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「多因素身份验证与账户恢复」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Secure Coding & OWASP Top 10 for Backend 课中编写并运行代码吗?

能。每节 Secure Coding & OWASP Top 10 for Backend 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 实施强访问控制
  2. 安全的用户身份验证机制
  3. 会话管理最佳实践
  4. 多因素身份验证与账户恢复
← 返回 Secure Coding & OWASP Top 10 for Backend