How to Test Two-Factor Authentication on Web (Complete Guide)

Two-factor authentication (2FA) is a critical security layer, safeguarding user accounts against unauthorized access. Inadequate testing of 2FA mechanisms can lead to significant user frustration, dat

March 11, 2026 · 6 min read · How-To Guides

Robust Two-Factor Authentication Testing for Web Applications

Two-factor authentication (2FA) is a critical security layer, safeguarding user accounts against unauthorized access. Inadequate testing of 2FA mechanisms can lead to significant user frustration, data breaches, and reputational damage. Common failures range from bypassed codes to lockout scenarios and accessibility barriers, directly impacting user trust and application security.

Comprehensive 2FA Test Cases

A thorough 2FA testing strategy must cover multiple facets of the user journey and potential failure points.

Happy Path Scenarios:

  1. Enter valid username and password.
  2. Receive a valid 2FA code (e.g., via SMS, email, authenticator app).
  3. Enter the valid 2FA code.
  4. Verify successful login and access to the authenticated section of the application.
  1. Enter valid username and password.
  2. Open authenticator app and retrieve the current time-based one-time password (TOTP).
  3. Enter the TOTP.
  4. Verify successful login.

Error Scenarios:

  1. Enter valid username and password.
  2. Receive a valid 2FA code.
  3. Enter an incorrect 2FA code.
  4. Verify an appropriate error message (e.g., "Invalid code") and that login is denied.
  1. Enter valid username and password.
  2. Receive a valid 2FA code.
  3. Wait for the code to expire (check the code's validity duration).
  4. Attempt to enter the expired code.
  5. Verify an appropriate error message (e.g., "Code has expired") and that login is denied.
  1. Enter valid username and password.
  2. Attempt to log in with multiple invalid 2FA codes consecutively (e.g., 5-10 times).
  3. Verify that the account is temporarily locked or that further attempts are rate-limited, preventing brute-force attacks.
  1. Initiate a login with valid credentials.
  2. Click the "Resend Code" option before entering the initial code.
  3. Verify that a new code is sent and that the previous code is invalidated.
  4. Enter the new, valid code and verify successful login.
  1. Initiate a login with valid credentials.
  2. Attempt to enter invalid 2FA codes a predefined number of times (e.g., 3-5).
  3. Verify that the account is locked and that the user receives a notification about the lockout, along with instructions for unlocking.

Edge Cases:

  1. Log in successfully on Device A with 2FA.
  2. Immediately attempt to log in on Device B with the same credentials and a valid 2FA code.
  3. Verify how the system handles concurrent sessions – does it invalidate the first, allow both, or prompt for re-authentication on the first?
  1. Initiate a login, receive a 2FA code.
  2. Navigate away from the login page or close the tab.
  3. Re-open the login page, enter valid credentials.
  4. Attempt to use the *previously received* code.
  5. Verify it's rejected if codes are session-specific.

Accessibility Considerations for Two-Factor Authentication:

  1. Navigate the 2FA process using a screen reader (e.g., NVDA, JAWS).
  2. Verify that all form fields, buttons, and error messages are clearly announced.
  3. Ensure instructions for receiving and entering codes are understandable.
  1. Complete the entire 2FA flow using only the keyboard (Tab, Shift+Tab, Enter, Spacebar).
  2. Verify that all interactive elements are focusable and operable.
  1. Check that error messages and instructions have sufficient color contrast against their background to be legible for users with low vision.
  1. For users who may take longer to input codes (e.g., due to motor impairments or cognitive differences), assess if the time limit is too restrictive. Evaluate options for extending time limits or providing alternative methods.

Manual Testing Approach

Manual testing of 2FA is essential for understanding user experience and uncovering nuanced issues.

  1. Setup: Ensure you have access to a test account with 2FA enabled and the necessary secondary authentication method (e.g., a phone for SMS, an authenticator app configured).
  2. Initial Login: Navigate to your web application's login page. Enter valid credentials for a user account.
  3. Second Factor Prompt: Observe the application's response. It should prompt for the second factor.
  4. Obtain and Enter Code:
  1. Input Code: Enter the obtained code into the designated field on the web application.
  2. Submit and Verify: Click the submit button. Confirm successful redirection to the authenticated area of the application.
  3. Error Condition Testing: Repeat steps 2-5 but intentionally introduce errors: use incorrect codes, expired codes, or exceed the allowed number of attempts. Document all error messages and system behaviors.
  4. Resend/Alternative Method Testing: If available, test the "Resend Code" functionality and any alternative methods (e.g., backup codes).
  5. Accessibility Testing: Utilize screen readers and keyboard-only navigation to assess usability for users with disabilities.
  6. Session Management: Test logging in from multiple browsers or incognito windows concurrently.

Automated Testing Approach for Web 2FA

Automated testing for 2FA requires careful consideration due to the dynamic nature of codes.


    import pyotp
    import time

    # Replace with your shared secret key for the test account
    # This secret is typically generated when setting up 2FA for the first time
    # and should be securely stored for automated testing.
    SECRET_KEY = "YOUR_SUPER_SECRET_KEY_HERE"
    totp = pyotp.TOTP(SECRET_KEY)

    # Get the current valid code
    current_code = totp.now()
    print(f"Current TOTP code: {current_code}")

    # In your test script, you would then use Playwright/Selenium
    # to enter this 'current_code' into the web application's input field.
    # page.locator('input[name="twoFactorCode"]').fill(current_code)

How SUSA Tests Two-Factor Authentication Autonomously

SUSA (SUSATest) approaches 2FA testing autonomously by simulating diverse user behaviors and leveraging its integrated capabilities.

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free