class ModelBackend
This is the default authentication backend used by Django. It authenticates using credentials consisting of a user identifier and password. For Django’s default user model, the user identifier is the username, for custom user models it is the field specified by USERNAME_FIELD (see Customizing Users and authentication).
It also handles the default permissions model as defined for User
and PermissionsMixin
.
has_perm()
, get_all_permissions()
, get_user_permissions()
, and get_group_permissions()
allow an object to be passed as a parameter for object-specific permissions, but this backend does not implement them other than returning an empty set of permissions if obj is not None
.
-
authenticate(username=None, password=None, **kwargs)
-
Tries to authenticate
username
withpassword
by callingUser.check_password
. If nousername
is provided, it tries to fetch a username fromkwargs
using the keyCustomUser.USERNAME_FIELD
. Returns an authenticated user orNone
.
-
get_user_permissions(user_obj, obj=None)
-
Returns the set of permission strings the
user_obj
has from their own user permissions. Returns an empty set ifis_anonymous
oris_active
isFalse
.
-
get_group_permissions(user_obj, obj=None)
-
Returns the set of permission strings the
user_obj
has from the permissions of the groups they belong. Returns an empty set ifis_anonymous
oris_active
isFalse
.
-
get_all_permissions(user_obj, obj=None)
-
Returns the set of permission strings the
user_obj
has, including both user permissions and group permissions. Returns an empty set ifis_anonymous
oris_active
isFalse
.
-
has_perm(user_obj, perm, obj=None)
-
Uses
get_all_permissions()
to check ifuser_obj
has the permission stringperm
. ReturnsFalse
if the user is notis_active
.
-
has_module_perms(self, user_obj, app_label)
-
Returns whether the
user_obj
has any permissions on the appapp_label
.
-
user_can_authenticate()
-
New in Django 1.10.
Returns whether the user is allowed to authenticate. To match the behavior of
AuthenticationForm
whichprohibits inactive users from logging in
, this method returnsFalse
for users withis_active=False
. Custom user models that don’t have anis_active
field are allowed.
Please login to continue.