Best way is to write your own authentication backend I think.

Check the docs:
http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs#writing-an-authentication-backend

This article might also give you a good idea:
http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/

The actual authenticate function might look something like this:

def authenticate(self, username=None, password=None):
        # authenticate with email
        try:
                user = self.user_class.objects.get(email=username)
                if user.check_password(password):
                        return user
        except self.user_class.DoesNotExist:
                # authentication with username
                try:
                        user = self.user_class.objects.get(username=username)
                        if user.check_password(password):
                                return user
                except self.user_class.DoesNotExist:
                        # neither nor succesfull, so no user exists
                        return None

Beware: During registration I have forbidden usernames that might look
like mail adresses (just unallow character @). Other than that there
might be the rare possibility that people can not login with their
username/password credentials if it username is the e-mail-adress used
by another account.

On Mar 31, 10:03 am, Rama Vadakattu <rama.vadaka...@gmail.com> wrote:
> The authentication model provided along with django is based on
> username.
>
> What to do to change the authentication based on email instead of
> username?
>
> To be more specific
> ~~~~~~~~~~~
>      With username authentication , to login user  we do the following
>
>      user = authenticate(name,password)
>      .......
>      login(request,user)
>
>      what to write for the above statements if we are authenticating
> using email?
>
>  For form
>  ~~~~~
> iam planning to write my own form which shows the fields
> email,password and the validation.
> Is this the correct approach?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to