How to add opt-in per-user two-factor auth in CakePHP using CakeDC/Users
The CakeDC/Users plugin offers built-in TOTP two-factor authentication for CakePHP, but its default configuration enforces 2FA for all users simultaneously rather than allowing individual opt-in. Developers can override this all-or-nothing behavior by implementing a custom OneTimePasswordAuthenticationChecker that checks a per-user database flag called two_steps before requiring the OTP step. A simple database migration adds the two_steps boolean column, defaulting to false so existing users are unaffected. A self-service enrollment screen lets signed-in users activate 2FA themselves by scanning a QR code and verifying a six-digit TOTP code, which then flips both the secret_verified and two_steps flags. Developers should also note a compatibility issue with the default QR code provider on modern dependencies, which can be resolved by switching to BaconQrCodeProvider with SVG output.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in