Explain how to implement a custom authentication backend in Django.
Instruction: Describe the process of creating and integrating a custom authentication system with Django's default user management.
Context: Candidates need to show their capability to extend or replace Django's built-in authentication mechanisms to accommodate unique requirements.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Use a custom backend only when the identity or eligibility policy needs it. Django calls authenticate(request, **credentials) and later uses get_user(user_id) to reload a session's user. Return a valid user or None as appropriate; do not replace password verification with a plain comparison.
For a concrete Django5.2 example, suppose this application's login is deliberately restricted to active staff users...