2
0

index.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. =============================
  2. User authentication in Django
  3. =============================
  4. .. toctree::
  5. :hidden:
  6. default
  7. passwords
  8. customizing
  9. .. module:: django.contrib.auth
  10. :synopsis: Django's authentication framework.
  11. Django comes with a user authentication system. It handles user accounts,
  12. groups, permissions and cookie-based user sessions. This section of the
  13. documentation explains how the default implementation works out of the box, as
  14. well as how to :doc:`extend and customize </topics/auth/customizing>` it to
  15. suit your project's needs.
  16. Overview
  17. ========
  18. The Django authentication system handles both authentication and authorization.
  19. Briefly, authentication verifies a user is who they claim to be, and
  20. authorization determines what an authenticated user is allowed to do. Here the
  21. term authentication is used to refer to both tasks.
  22. The auth system consists of:
  23. * Users
  24. * Permissions: Binary (yes/no) flags designating whether a user may perform
  25. a certain task.
  26. * Groups: A generic way of applying labels and permissions to more than one
  27. user.
  28. * A configurable password hashing system
  29. * Forms and view tools for logging in users, or restricting content
  30. * A pluggable backend system
  31. The authentication system in Django aims to be very generic and doesn't provide
  32. some features commonly found in web authentication systems. Solutions for some
  33. of these common problems have been implemented in third-party packages:
  34. * Password strength checking
  35. * Throttling of login attempts
  36. * Authentication against third-parties (OAuth, for example)
  37. Installation
  38. ============
  39. Authentication support is bundled as a Django contrib module in
  40. ``django.contrib.auth``. By default, the required configuration is already
  41. included in the :file:`settings.py` generated by :djadmin:`django-admin
  42. startproject <startproject>`, these consist of two items listed in your
  43. :setting:`INSTALLED_APPS` setting:
  44. 1. ``'django.contrib.auth'`` contains the core of the authentication framework,
  45. and its default models.
  46. 2. ``'django.contrib.contenttypes'`` is the Django :doc:`content type system
  47. </ref/contrib/contenttypes>`, which allows permissions to be associated with
  48. models you create.
  49. and these items in your :setting:`MIDDLEWARE_CLASSES` setting:
  50. 1. :class:`~django.contrib.sessions.middleware.SessionMiddleware` manages
  51. :doc:`sessions </topics/http/sessions>` across requests.
  52. 2. :class:`~django.contrib.auth.middleware.AuthenticationMiddleware` associates
  53. users with requests using sessions.
  54. 3. :class:`~django.contrib.auth.middleware.SessionAuthenticationMiddleware`
  55. logs users out of their other sessions after a password change.
  56. With these settings in place, running the command ``manage.py migrate`` creates
  57. the necessary database tables for auth related models and permissions for any
  58. models defined in your installed apps.
  59. Usage
  60. =====
  61. :doc:`Using Django's default implementation <default>`
  62. * :ref:`Working with User objects <user-objects>`
  63. * :ref:`Permissions and authorization <topic-authorization>`
  64. * :ref:`Authentication in web requests <auth-web-requests>`
  65. * :ref:`Managing users in the admin <auth-admin>`
  66. :doc:`API reference for the default implementation </ref/contrib/auth>`
  67. :doc:`Customizing Users and authentication <customizing>`
  68. :doc:`Password management in Django <passwords>`