{% extends "base.html" %} {% load static %} {% block title %}Two-Factor Authentication Settings - {{ project_name }}{% endblock %} {% block extra_head %} {% endblock %} {% block content %}

Two-Factor Authentication

Enhanced Security for Your Account

Infrastructure Ready - Implementation in Progress

The two-factor authentication system infrastructure is fully prepared and ready for implementation.

Current Status

{% if system_enabled %} System Enabled
Two-factor authentication system is available for use
{% else %} System Disabled
Two-factor authentication system is not yet available
{% endif %}
{% if is_enabled %} Enabled
Two-factor authentication is enabled for your account
{% else %} Disabled
Two-factor authentication is not enabled for your account
{% endif %}
{% if has_backup_codes %} {{ backup_codes_count }} Generated {% else %} Not Generated {% endif %}
{{ issuer_name }}

🛠️ Implementation Readiness

✅ Infrastructure Complete

  • ✅ Database models created
  • ✅ Settings configuration ready
  • ✅ View structure prepared
  • ✅ Template framework established
  • ✅ Backup code system functional
  • ✅ API endpoints structured

⏳ Implementation Pending

  • ⏳ TOTP library integration
  • ⏳ QR code generation
  • ⏳ Verification workflow
  • ⏳ Setup wizard
  • ⏳ Authentication middleware
  • ⏳ Recovery mechanisms

Required Dependencies:

pip install pyotp>=2.8.0 qrcode>=7.4.0 Pillow>=10.0.0

🔧 Preparation Actions

Test the infrastructure components that are ready:

Create emergency backup codes for account recovery
Configure time-based one-time password authentication (feature coming soon)
Test authentication code verification (feature coming soon)

🔑 Backup Codes Generated

Store these codes in a secure location. Each code can only be used once.

📚 Implementation Guide

Next Steps for Full Implementation:

  1. Install Dependencies:
    pip install pyotp qrcode[pil]
  2. TOTP Secret Generation:
    import pyotp
    secret = pyotp.random_base32()
    totp = pyotp.TOTP(secret)
  3. QR Code Generation:
    import qrcode
    provisioning_uri = totp.provisioning_uri(
        user.email, 
        issuer_name="{{ issuer_name }}"
    )
    qr = qrcode.make(provisioning_uri)
  4. Verification Logic:
    totp = pyotp.TOTP(user.two_factor_auth.secret_key)
    is_valid = totp.verify(user_provided_code)
  5. Middleware Integration:

    Add 2FA verification middleware to check codes after login

💡 Framework Ready: All the database models, views, and templates are prepared. You just need to integrate the TOTP library and implement the verification workflow.

{% endblock %}