Django provides a simple way to define your own authentication backends. An authentication backend is a class that provides the following two methods:
- authenticate(): It takes the request object and user credentials as parameters. It has to return a user object that matches those credentials if the credentials are valid, or None oth- erwise. The request parameter is an HttpRequest object, or None if it’s not provided to the authenticate() function.
- get_user(): It takes a user ID parameter and has to return a user object.
Creating a custom authentication backend is as simple as writing a Python class that implements both methods. Let’s create an authentication backend to allow users to authenticate on the site using their email address instead of their username.
Deliverables
- Implementation should be done in the
authentication.py file
Django provides a simple way to define your own authentication backends. An authentication backend is a class that provides the following two methods:
Creating a custom authentication backend is as simple as writing a Python class that implements both methods. Let’s create an authentication backend to allow users to authenticate on the site using their email address instead of their username.
Deliverables
authentication.pyfile