Login

Tag "authentication"

Snippet List

Use email addresses for user name

Django's built in authentication system requires the username to be alpha-numeric only. Therefore, email addresses are invalid. However, in many cases, you would like to use an email address as the username. This snippet allows you to do so. It has the added benefit that if you want to continue using the regular username format, you can do that too. It's the best of both worlds! To make sure propoer credit is given, this code is modified from a django group posting from Vasily Sulatskov. To use this file, save it in your project as something like: email-auth.py Then, add the following lines to your settings.py file: AUTHENTICATION_BACKENDS = ( 'yourproject.email-auth.EmailBackend', ) You can see a full implementation [here] (http://www.satchmoproject.com/trac/browser/satchmo/trunk/satchmo)

  • authentication
Read More

apache authentication via cookies

Enables cookie based authentication with apache. I needed user authentication for some static files, but couldn't use the method described [here](http://www.djangoproject.com/documentation/apache_auth/) as this prompts the user for his credentials, making him log in twice. There is some overhead in the code, because it runs all request middleware components (only session and auth would be needed). All arguments described in the link above are supported. I use it like this in the apache config: <Location "/protected/location"> PythonPath "['/path/to/proj/'] + sys.path" PythonOption DJANGO_SETTINGS_MODULE myproj.settings PythonOption DjangoPermissionName '<permission.codename>' PythonAccessHandler my_proj.modpython #this should point to accesshandler SetHandler None </Location>

  • authentication
  • apache
Read More

Basic HTTP Authentication

A patch (against django svn trunk [4649](http://code.djangoproject.com/browser/django/trunk/?rev=4649)) that allows users to log in with Basic HTTP Authentication i.s.o. login forms using some simple middleware (entire patch is ~50 lines). I was unaware of http://code.djangoproject.com/wiki/GenericAuthorization so I'm not sure about its usefulness in the long run. You can enable it by including 'django.contrib.auth.middleware.BasicAuthenticationMiddleware' in your MIDDLEWARE_CLASSES and then adding the following lines in your settings.py: BASIC_WWW_AUTHENTICATION = True WWW_AUTHENTICATION_REALM = "djangolures.com" Updated: See also http://code.djangoproject.com/ticket/3609 (patch now availble here as well).

  • middleware
  • django
  • http
  • basic
  • authentication
Read More

50 snippets posted so far.