{"title":"User authentication in Django","version":"5.1","locale":"el","docname":"topics/auth/index","url":"/el/5.1/topics/auth/","canonical":"https://djangodocs.dev/el/5.1/topics/auth/","summary":"Django comes with a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This section of the documentation…","html":"<h1>User authentication in Django<a class=\"heading-anchor\" href=\"#user-authentication-in-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<div class=\"toctree-wrapper compound\">\n</div>\n<p id=\"module-django.contrib.auth\">Django comes with a user authentication system. It handles user accounts,\ngroups, permissions and cookie-based user sessions. This section of the\ndocumentation explains how the default implementation works out of the box, as\nwell as how to <a class=\"reference internal\" href=\"/el/5.1/topics/auth/customizing/\"><span class=\"doc\">extend and customize</span></a> it to\nsuit your project’s needs.</p>\n<section id=\"overview\">\n<h2>Overview<a class=\"heading-anchor\" href=\"#overview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The Django authentication system handles both authentication and authorization.\nBriefly, authentication verifies a user is who they claim to be, and\nauthorization determines what an authenticated user is allowed to do. Here the\nterm authentication is used to refer to both tasks.</p>\n<p>The auth system consists of:</p>\n<ul class=\"simple\">\n<li><p>Users</p></li>\n<li><p>Permissions: Binary (yes/no) flags designating whether a user may perform\na certain task.</p></li>\n<li><p>Groups: A generic way of applying labels and permissions to more than one\nuser.</p></li>\n<li><p>A configurable password hashing system</p></li>\n<li><p>Forms and view tools for logging in users, or restricting content</p></li>\n<li><p>A pluggable backend system</p></li>\n</ul>\n<p>The authentication system in Django aims to be very generic and doesn’t provide\nsome features commonly found in web authentication systems. Solutions for some\nof these common problems have been implemented in third-party packages:</p>\n<ul class=\"simple\">\n<li><p>Password strength checking</p></li>\n<li><p>Throttling of login attempts</p></li>\n<li><p>Authentication against third-parties (OAuth, for example)</p></li>\n<li><p>Object-level permissions</p></li>\n</ul>\n</section>\n<section id=\"installation\">\n<h2>Installation<a class=\"heading-anchor\" href=\"#installation\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Authentication support is bundled as a Django contrib module in\n<code class=\"docutils literal notranslate\"><span class=\"pre\">django.contrib.auth</span></code>. By default, the required configuration is already\nincluded in the <code class=\"file docutils literal notranslate\"><span class=\"pre\">settings.py</span></code> generated by <a class=\"reference internal\" href=\"/el/5.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\"><span class=\"pre\">django-admin</span>\n<span class=\"pre\">startproject</span></code></a>, these consist of two items listed in your\n<a class=\"reference internal\" href=\"/el/5.1/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">INSTALLED_APPS</span></code></a> setting:</p>\n<ol class=\"arabic simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.auth'</span></code> contains the core of the authentication framework,\nand its default models.</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">'django.contrib.contenttypes'</span></code> is the Django <a class=\"reference internal\" href=\"/el/5.1/ref/contrib/contenttypes/\"><span class=\"doc\">content type system</span></a>, which allows permissions to be associated with\nmodels you create.</p></li>\n</ol>\n<p>and these items in your <a class=\"reference internal\" href=\"/el/5.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\"><span class=\"pre\">MIDDLEWARE</span></code></a> setting:</p>\n<ol class=\"arabic simple\">\n<li><p><a class=\"reference internal\" href=\"/el/5.1/ref/middleware/#django.contrib.sessions.middleware.SessionMiddleware\" title=\"django.contrib.sessions.middleware.SessionMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">SessionMiddleware</span></code></a> manages\n<a class=\"reference internal\" href=\"/el/5.1/topics/http/sessions/\"><span class=\"doc\">sessions</span></a> across requests.</p></li>\n<li><p><a class=\"reference internal\" href=\"/el/5.1/ref/middleware/#django.contrib.auth.middleware.AuthenticationMiddleware\" title=\"django.contrib.auth.middleware.AuthenticationMiddleware\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">AuthenticationMiddleware</span></code></a> associates\nusers with requests using sessions.</p></li>\n</ol>\n<p>With these settings in place, running the command <code class=\"docutils literal notranslate\"><span class=\"pre\">manage.py</span> <span class=\"pre\">migrate</span></code> creates\nthe necessary database tables for auth related models and permissions for any\nmodels defined in your installed apps.</p>\n</section>\n<section id=\"usage\">\n<h2>Usage<a class=\"heading-anchor\" href=\"#usage\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/default/\"><span class=\"doc\">Using Django’s default implementation</span></a></p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/default/#user-objects\"><span class=\"std std-ref\">Working with User objects</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/default/#topic-authorization\"><span class=\"std std-ref\">Permissions and authorization</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/default/#auth-web-requests\"><span class=\"std std-ref\">Authentication in web requests</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/default/#auth-admin\"><span class=\"std std-ref\">Managing users in the admin</span></a></p></li>\n</ul>\n<p><a class=\"reference internal\" href=\"/el/5.1/ref/contrib/auth/\"><span class=\"doc\">API reference for the default implementation</span></a></p>\n<p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/customizing/\"><span class=\"doc\">Customizing Users and authentication</span></a></p>\n<p><a class=\"reference internal\" href=\"/el/5.1/topics/auth/passwords/\"><span class=\"doc\">Password management in Django</span></a></p>\n</section>","rootId":"user-authentication-in-django","toc":[{"title":"Overview","anchor":"overview","children":[]},{"title":"Installation","anchor":"installation","children":[]},{"title":"Usage","anchor":"usage","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Using Django","url":"/el/5.1/topics/"}],"prev":{"docname":"topics/testing/advanced","title":"Advanced testing topics","url":"/el/5.1/topics/testing/advanced/"},"next":{"docname":"topics/auth/default","title":"Using the Django authentication system","url":"/el/5.1/topics/auth/default/"},"formats":{"html":"/el/5.1/topics/auth/","markdown":"/el/5.1/topics/auth.md","json":"/el/5.1/topics/auth.json"},"source":"https://github.com/django/django/blob/stable/5.1.x/docs/topics/auth/index.txt","official":"https://docs.djangoproject.com/el/5.1/topics/auth/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}