python django user not authenticated with user object
Question: Ok I am facing this problem with authentication

    
    
    user_profile = UserProfile.objects.get(email="some@email.com")
    new_password = form.cleaned_data['new_password']
    user_profile.user.set_password(new_password)
    user_profile.user.save()
    user = authenticate(username=user_profile.user.username, password=new_password)
    print(user)
    

When I print user it gives `None`

Why the user is not being authenticated?


Answer: The authenticate function from `django.contrib.auth` returns an instance of
`django.contrib.auth.models.User` class if the credentials match or None if
they don't.

I guess no user with username and password provided by you exists. That is why
you are getting None.

I suggest going to the shell and running:

    
    
    from django.contrib.auth.models import User
    from django.contrib.auth.hashers import make_password
    password = make_password("your_password")
    user = User.objects.filter(username="username",password=password)
    

and see what user holds.

