---
title: "Django でのユーザー認証"
version: 1.10
locale: ja
source: https://docs.djangoproject.com/ja/1.10/topics/auth/
canonical: https://djangodocs.dev/ja/1.10/topics/auth/
---
# Django でのユーザー認証

Django はユーザー認証システムを搭載しています。ユーザーアカウント、グループ、パーミッション、そしてCookieベースのユーザーセッションを制御します。このドキュメントのこのセクションでは、デフォルトの実装がどう機能するか、またあなたのプロジェクトのニーズに対応させるための [拡張とカスタマイズ](/ja/1.10/topics/auth/customizing/) の方法を説明しています。

## オーバービュー

Django の認証システムは、認証と権限の両方を扱います。簡単に言うと、認証はユーザーが誰であるかを立証し、権限は立証されたユーザーが何をすることが許されているかを決定します。ここでは、認証という用語は両方のタスクを指すために使われます。

認証システムを構成するものは以下の通りです:

- ユーザ
- パーミッション: ユーザが特定のタスクを実行できるかどうかを指定するバイナリ (yes/no) フラグ
- グループ: 複数のユーザーにラベルとパーミッションを付与する一般的な方法
- 設定変更可能なパスワードハッシュシステム
- ユーザーログインのためのフォームやビューツール、もしくは内容の制限
- プラガブルなバックエンドシステム

Django の認証システムは一般的であることを狙いとしており、ウェブ上の認証システムで見られるようないくつかの機能を有していません。これらに共通する問題の解決策は、サードパーティのパッケージにて実装されます。

- パスワード強度のチェック
- ログイン試行数の制限
- サードパーティに対する認証 (OAuthなど)

## インストール

Authentication support is bundled as a Django contrib module in
`django.contrib.auth`. By default, the required configuration is already
included in the `settings.py` generated by [`django-admin
startproject`](/ja/1.10/ref/django-admin/#django-admin-startproject), these consist of two items listed in your
[`INSTALLED_APPS`](/ja/1.10/ref/settings/#std-setting-INSTALLED_APPS) setting:

1. `'django.contrib.auth'` contains the core of the authentication framework,
   and its default models.
2. `'django.contrib.contenttypes'` is the Django [content type system](/ja/1.10/ref/contrib/contenttypes/), which allows permissions to be associated with
   models you create.

and these items in your [`MIDDLEWARE`](/ja/1.10/ref/settings/#std-setting-MIDDLEWARE) setting:

1. [`SessionMiddleware`](/ja/1.10/ref/middleware/#django.contrib.sessions.middleware.SessionMiddleware) manages
   [sessions](/ja/1.10/topics/http/sessions/) across requests.
2. [`AuthenticationMiddleware`](/ja/1.10/ref/middleware/#django.contrib.auth.middleware.AuthenticationMiddleware) associates
   users with requests using sessions.

With these settings in place, running the command `manage.py migrate` creates
the necessary database tables for auth related models and permissions for any
models defined in your installed apps.

## 使い方

[Using Django's default implementation](/ja/1.10/topics/auth/default/)

- [Working with User objects](/ja/1.10/topics/auth/default/#user-objects)
- [Permissions and authorization](/ja/1.10/topics/auth/default/#topic-authorization)
- [Authentication in web requests](/ja/1.10/topics/auth/default/#auth-web-requests)
- [Managing users in the admin](/ja/1.10/topics/auth/default/#auth-admin)

[API reference for the default implementation](/ja/1.10/ref/contrib/auth/)

[Customizing Users and authentication](/ja/1.10/topics/auth/customizing/)

[Password management in Django](/ja/1.10/topics/auth/passwords/)
