[PR #22455] feat: implement multi-factor authentication (MFA) support #29936

Closed
opened 2026-02-21 20:46:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/22455

State: closed
Merged: No


Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This PR implements Multi-Factor Authentication (MFA) support for Dify, enhancing security by allowing users to enable two-factor authentication on their accounts. This is a re-submission of #22415,
which was closed due to merge conflicts with the main branch. The changes have been properly rebased on the latest main branch.

Key features implemented:

  • TOTP-based two-factor authentication using authenticator apps (Google Authenticator, Authy, etc.)
  • Backup codes for account recovery
  • Secure MFA setup and management flow
  • MFA verification integrated into the login process

Technical implementation:

  • Backend: New MFA models, services, and API endpoints with comprehensive security measures
  • Frontend: Intuitive UI for MFA setup, QR code generation, and verification
  • Database: New tables for MFA settings and encrypted secret storage
  • Testing: Full test coverage for both API and UI components

Screenshots

MFA Setup Flow

Step Screenshot
1. Enable MFA 01-enable
2. QR Code Setup (blurred for security) 02-qr
3. First TOTP Verification 03-first-totp
4. Backup Codes (masked as AAAAAAAA) 04-backup-codes

MFA Login

Step Screenshot
MFA Verification during login 05-login-totp

MFA Management

Step Screenshot
Disable MFA option 06-disable
Password confirmation for disable 07-disable-password

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Additional Notes

**Original Pull Request:** https://github.com/langgenius/dify/pull/22455 **State:** closed **Merged:** No --- > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 2. Ensure there is an associated issue and you have been assigned to it > 3. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR implements Multi-Factor Authentication (MFA) support for Dify, enhancing security by allowing users to enable two-factor authentication on their accounts. This is a re-submission of #22415, which was closed due to merge conflicts with the main branch. The changes have been properly rebased on the latest main branch. ### Key features implemented: - TOTP-based two-factor authentication using authenticator apps (Google Authenticator, Authy, etc.) - Backup codes for account recovery - Secure MFA setup and management flow - MFA verification integrated into the login process ### Technical implementation: - **Backend**: New MFA models, services, and API endpoints with comprehensive security measures - **Frontend**: Intuitive UI for MFA setup, QR code generation, and verification - **Database**: New tables for MFA settings and encrypted secret storage - **Testing**: Full test coverage for both API and UI components ## Screenshots ### MFA Setup Flow | Step | Screenshot | |------|------------| | 1. Enable MFA | <img width="800" alt="01-enable" src="https://github.com/user-attachments/assets/6b7caa7c-cbf8-4839-b4b8-cd3a1dc75290" /> | | 2. QR Code Setup (blurred for security) | <img width="800" alt="02-qr" src="https://github.com/user-attachments/assets/cfa3695d-9ea0-4b91-8e25-36dce4c33751" /> | | 3. First TOTP Verification | <img width="800" alt="03-first-totp" src="https://github.com/user-attachments/assets/ee7ed172-8a61-46a3-8e8d-7612baeef411" /> | | 4. Backup Codes (masked as AAAAAAAA) | <img width="800" alt="04-backup-codes" src="https://github.com/user-attachments/assets/3534d68d-4931-4113-9827-a8a5b1eb27d7" /> | ### MFA Login | Step | Screenshot | |------|------------| | MFA Verification during login | <img width="800" alt="05-login-totp" src="https://github.com/user-attachments/assets/290b66bf-34dc-4af4-8e15-5af1075fd486" /> | ### MFA Management | Step | Screenshot | |------|------------| | Disable MFA option | <img width="800" alt="06-disable" src="https://github.com/user-attachments/assets/139693c1-0271-4eae-a13e-ce3f8b1fa01d" /> | | Password confirmation for disable | <img width="800" alt="07-disable-password" src="https://github.com/user-attachments/assets/5362d6ca-ada4-46a6-bd5a-dd2982da2d35" /> | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods ## Additional Notes - All tests pass successfully (API: 18/18 MFA tests, Web: 9/9 MFA tests) - No breaking changes - MFA is optional and can be enabled by users - Supersedes #22415
yindo added the pull-request label 2026-02-21 20:46:32 -05:00
yindo closed this issue 2026-02-21 20:46:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#29936