Django: authenticate the user
<p>I have the following code:</p>

<p><strong># creating user:</strong></p>

<pre><code>def create_user(request):
    if request.method == 'POST':
        user_info = forms.UserInfoForm(request.POST)
        if user_info.is_valid():
            cleaned_info = user_info.cleaned_data
            User.objects.create_user(username=cleaned_info['username'], password=cleaned_info['password'])
   render(.......)
</code></pre>

<p>This works. I can check the auth_user and I see the username and password along with all the other fields created and added.</p>

<p>Now, I try to authenticate the user with the following code after creating user with <strong>username='testcase' and password='test':</strong> using above code.</p>

<p><strong># Authenticate User</strong></p>

<pre><code>def get_entry(request):
    if request.method == 'POST':
        user = authenticate(username='testcase', password='test')
        if user:
            .........
</code></pre>

<p>The user is always returned as none. What is going on? I am running django 1.10.2. </p>

<p><strong>Update:</strong></p>

<p>I can see the user created by create_user function when I log in admin. The status was not staff(as it was supposed to be). I changed that to staff to see if that was causing problem but still the get_entry method yields none for user.
It is frustrating. I don't really know what I am doing wrong.</p>

<p>Your code seems to be correct. </p>

<p>The problem might be in the way the params are being passed to your <code>create_user</code> view (Param passing in <code>get_entry</code> view highly unlikely to be a problem since the params <code>username</code> and <code>password</code> are hard-coded).</p>

<p>Try printing out <code>username</code> and <code>password</code> before passing them to <code>User.objects.create_user()</code>, since it's possible that the <code>password</code> field is not being saved properly and/or empty <code>password</code> is being passed, and Django might be creating a hash for the empty password.</p>

<p>P.S.: This is just a speculation, need your response over this for further diagnosis of the issue.</p>

python django