.. index:: pair: syntax; pep8 ================================================ Ecrire un backend custom pour l'authentification ================================================ Un peu de doc ============= + `settings - AUTHENTICATION_BACKENDS`_ |en_flag| + `documentation sur les backends d'authentification`_ |en_flag| Exemples concrets ================= Auth LDAP --------- Besoin d'une authentification LDAP ? Hop, `un article à lire`_ |en_flag|. Username insensible à la casse ------------------------------ Dans un fichier ``your_project/your_app/backends.py``: :: from django.contrib.auth.models import User from django.contrib.auth.backends import ModelBackend as DjangoModelBackend class ModelBackend(DjangoModelBackend): def authenticate(self, username=None, password=None): """ Case insensitive username """ try: user = User.objects.get(username__iexact=username) if user.check_password(password): return user except User.DoesNotExist: return None Dans le fichier ``settings.py``: :: # Custom Auth Backend : case insensitive username AUTHENTICATION_BACKENDS = ( 'your_project.your_app.backends.ModelBackend', ) En savoir plus ============== ... Lire le code ! ``django/contrib/auth/__init__.py`` :Author: Lauréline Guérin :Contact: laureline.guerin_at_makina-corpus.org :LastUpdate: 07/06/2008 .. _`settings - AUTHENTICATION_BACKENDS`: http://www.djangoproject.com/documentation/settings/#authentication-backends .. _`documentation sur les backends d'authentification`: http://www.djangoproject.com/documentation/authentication/#other-authentication-sources .. _`un article à lire`: http://www.carthage.edu/webdev/?p=12 .. |en_flag| image:: http://doc.makina-corpus.org/python/_static/en.png