Django - authenticate() return None
<p>I read many of topic about this problem and the problem is always there. When I submit my login form, the authenticate function() returns None. I used the function set_password() for the registration and it changes nothing. </p>

<p>Here is my code (also <a href="https://repl.it/CbTW/0" rel="nofollow">here</a>):</p>

<pre><code>from django.contrib.auth.models import User
from django.shortcuts import render
from forms import LoginForm, RegistrationForm
from django.contrib import auth

def login(request):
    state = 0 # 0 = initialisation / 1 = OK / 2 = BAD_PW
    form = LoginForm()
    if request.method == 'POST':
        error = False
        if request.method == "POST":
            form = LoginForm(request.POST)
            if form.is_valid():
                email = form.cleaned_data["email"]
                password = form.cleaned_data["password"]
                user = auth.authenticate(email=email,
                                    password=password)
                if user:
                    auth.login(request, user)
                    state = 1
                else:
                    state = 2
                    print "login state " + str(state)
        else:
            form = LoginForm()

    return render(request, "birneo/login.html", locals())

def register(request):
    state = 0
    form = RegistrationForm()
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User()
            user.username = form.cleaned_data['username']
            user.email = form.cleaned_data['email']
            user.set_password(form.cleaned_data['password'])
            user.save()
            state = 1
            form = RegistrationForm()
        else:
            form = RegistrationForm()

    return render(request, "birneo/register.html", locals())
</code></pre>