Search code examples
djangodjango-allauth

Django-allauth and password strength on sign up


There is a way to django-allauth take care of password strength checking on sign up?

I saw that it is possible to set the size of the password configuring ACCOUNT_PASSWORD_MIN_LENGTH in settings.py, but I also like to check other usual things like:

  • There is at least one uppercase letter
  • There is at least one digit
  • There is at least one special character

There is a way to do that with django-allauth?

Thanks in advance.


Solution

  • You can do this by overriding the default adapter (via ACCOUNT_ADAPTER), like this:

    from allauth.account.adapter import DefaultAccountAdapter
    
    class MyAccountAdapter(DefaultAccountAdapter):
    
        def clean_password(self, password):
            # Insert your rules here
    

    Note that Django has recently added support for custom password validators. This mechanism will be supported in allauth as well, keep an eye on issue https://github.com/pennersr/django-allauth/issues/1233 for that.