django-dual-authentication

Allows authentication with either a username or an email address.


License
MIT
Install
pip install django-dual-authentication==1.2.1

Documentation

Django-dual-authentication

This package allows to authenticate a user with either a username an email address, or both. It overrides Django authenticate method, so it should work in almost any case of use, without touch anything else.

Supported versions:

  • Python >= 2.7
  • Django >= 1.5

Installation

Run:

pip install django-dual-authentication

Then, add this line to your settings.py:

AUTHENTICATION_BACKENDS = ['django-dual-authentication.backends.DualAuthentication']

Quick and painless, right?

Settings

  • AUTHENTICATION_METHOD: You can authenticate your users by 'username', 'email', 'both'. Default: 'both'.
  • AUTHENTICATION_CASE_SENSITIVE: You can choose 'username', 'email', 'both', 'none'. Default: 'username'.

Common issues

We've been reported about users having problems with MySQL and dual-authentication case sensitive option. This is because mysql is case-insensitive by default. So, if you need case sensitive authentication, probably you'd prefer avoid this database engine.

Also, note that if you combine certain options like AUTHENTICATION_METHOD = 'username' and AUTHENTICATION_CASE_SENSITIVE = 'username', then might be a good idea check if a not case sensitive user already exists, for your registation form's username field. Other way, users having the same username with different capital letters, will not be able to login, for obvious reasons.

Finally, note that 'email' and 'both', are meant for very specific border cases. All email adresses of the internet are case insensitive, so it's recommended to use the values 'none' or 'username'.

Testing

  • Clone this repository.
  • Open testproject directory.
  • Run syncdb or migrate depending your django version, and runserver.
  • Open http://localhost:8000/admin/ and try to login.

Updates

  • Dec 2014: Stable release
  • Dec 2015: All it's working fine. No changes.
  • Dec 2016: All it's working fine. No changes.
  • Dec 2017: All it's working fine. No changes.
  • Dec 2018: All it's working fine. No changes.
  • Apr 2019: Added support for django 2.0+ and Python ~3.7.