django-two-factor-auth icon indicating copy to clipboard operation
django-two-factor-auth copied to clipboard

Authentication backend's authenticate() method is called twice during a unsuccessful authentication

Open VGSebastian opened this issue 6 years ago • 2 comments
trafficstars

Similar to the behavior described in #221 for successful authentication, on unsuccessful authentication, the authenticate method is called twice:

  • formtools.wizard.views.WizardView.post()
    • self.get_form_list() -> two_factor.views.core.LoginView.get_user() ...
    • form.is_valid()

Expected Behavior

Authentication should stop after the first unsuccessful authentication attempt using these credentials. If the external authentication backend locks a user after a certain number of failed attempts, each authentication attempt using the django application that uses 2fa leads to two failed attempts in the external system and hence locking the user earlier than expected.

Current Behavior

On unsuccessful authentication, the wrong credentials are sent twice to the authentication backend.

Steps to Reproduce (for bugs)

  1. Create a custom authentication backend based on the default ModelBackend
  2. Log calls to authenticate()
  3. Try to login with wrong credentials and check the log for 2 calls to authenticate()

Context

I want to avoid locking users too early in external authentication systems.

Your Environment

  • Browser and version: Firefox 70.0.1
  • Python version: 3.6
  • Django version: 2.2.2
  • django-otp version: 0.72
  • django-two-factor-auth version: 1.9.1

VGSebastian avatar Nov 21 '19 12:11 VGSebastian

Am also observing the same behavior using identical reproduction steps.

CodeSpent avatar Oct 02 '20 21:10 CodeSpent

@CodeSpent have you tried with a more recent version of django-two-factor-auth?

moggers87 avatar Oct 03 '20 14:10 moggers87