Django Authentication 6.1

Last reviewed Sep 24, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. Python 3155 lines · 3.8K tokens
  2. Django 6.1140 lines · 4.1K tokens
  3. Django Authentication 6.183 lines · 3.6K tokens
Total378 lines · 11.4K tokens

CWE Coverage

  • 20
  • 23
  • 36
  • 59
  • 73
  • 78
  • 79
  • 89
  • 95
  • 117
  • 201
  • 203
  • 208
  • 209
  • 214
  • 250
  • 287
  • 288
  • 295
  • 307
  • 319
  • 328
  • 338
  • 347
  • 352
  • 362
  • 367
  • 379
  • 384
  • 409
  • 416
  • 426
  • 427
  • 434
  • 470
  • 502
  • 521
  • 524
  • 532
  • 601
  • 611
  • 613
  • 614
  • 620
  • 639
  • 640
  • 674
  • 732
  • 770
  • 772
  • 776
  • 778
  • 798
  • 807
  • 829
  • 841
  • 862
  • 863
  • 915
  • 916
  • 918
  • 942
  • 1004
  • 1021
  • 1104
  • 1275
  • 1333
  • 1336
  • 1395

Prompt Preview

Apply the Django 6.1 prompt first. These additional rules cover Django 6.1.1 authentication on Python 3.12–3.14, using the latest supported Python micro release.

Identity establishment and backend policy

  • Treat login() and alogin() as session-establishment APIs: they do not verify credentials, reject inactive users, or enforce MFA. A loaded user object's is_authenticated is always true; it is not proof that the caller authenticated as that user.
  • Review AUTHENTICATION_BACKENDS in order: the first successful compatible backend wins. Return None for unverified credentials and raise PermissionDenied for a terminal rejection that must prevent later backends from accepting them.
  • Keep any explicit login(..., backend=...) path under server control. Preserve the backend selected by authenticate() rather than letting a request choose which backend will reload its session identity.
  • Enforce suspension in custom authenticate() and get_user() implementations and their async counterparts. Default backends reject is_active=False, but models without is_active and the AllowAllUsers*Backend variants remove that protection; AuthenticationForm.confirm_login_allowed() is a separate form-level check.
  • When subclassing ModelBackend or RemoteUserBackend, review native async implementations as well as sync overrides. Overriding authenticate(), get_user(), or permission methods alone need not affect aauthenticate(), aget_user(), or async permission checks.
  • Use get_user_model() and settings.AUTH_USER_MODEL for identity lookups and