2FA Diagram
Last Updated: May 19, 2025
This document provides an overview of the two-factor authentication (2FA) system in the Typus Development Framework.
Overview
Two-factor authentication (2FA) adds an extra layer of security to the authentication process by requiring users to provide two different authentication factors: something they know (password) and something they have (a mobile device or email access).
2FA Methods
Typus supports multiple 2FA methods:
- APP: Time-based one-time passwords (TOTP) using authenticator apps like Google Authenticator or Authy
- EMAIL: One-time codes sent via email
2FA Setup Flow
2FA Login Flow
APP Method (TOTP)
The APP method uses the Time-based One-Time Password (TOTP) algorithm:
Setup:
- System generates a secret key
- User scans QR code with authenticator app
- User verifies setup by entering a code from the app
Verification:
- User enters the current code from their authenticator app
- System validates the code against the stored secret
- Code changes every 30 seconds for security
EMAIL Method
The EMAIL method uses one-time codes sent via email:
Setup:
- System sends a verification code to the user's email
- User enters the code to confirm access to the email
Verification:
- System generates a random 6-digit code
- Code is sent to the user's email address
- User enters the code to complete authentication
- Codes expire after 5 minutes
Security Considerations
- Secret Storage: 2FA secrets are securely stored in the database
- Temporary Tokens: Temporary tokens are used during the 2FA verification process
- Rate Limiting: Verification attempts are rate-limited to prevent brute force attacks
- Expiration: Verification codes expire after a short period
- Backup Codes: Recovery options are available if users lose access to their 2FA method
Disabling 2FA
Users can disable 2FA through their account settings:
Implementation Details
The 2FA system is implemented using a strategy pattern:
- Common Interface: All 2FA methods implement a common interface
- Method Selection: The appropriate method is selected based on user preferences
- Extensibility: New 2FA methods can be added by implementing the interface
Conclusion
The two-factor authentication system in Typus provides a robust security layer that can be customized to meet different security requirements. By supporting multiple 2FA methods, the system offers flexibility while maintaining strong security standards.