# Authenticate return None

**URL:** <https://forum.djangoproject.com/t/authenticate-return-none/32230>\
**Category:** Mystery Errors\
**Created:** [June 19, 2024, 10:22am UTC](https://forum.djangoproject.com/t/authenticate-return-none/32230 "2024-06-19T10:22:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phutuan123vn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/phutuan123vn/32/22046_2.png) [@phutuan123vn](https://forum.djangoproject.com/u/phutuan123vn)\
**Post date:** [June 19, 2024, 10:22am UTC](https://forum.djangoproject.com/t/authenticate-return-none/32230/1 "2024-06-19T10:22:56Z")

</div>

I always get None value from authenticate function through I have registered user when testing by using Postman and I also try using Django Shell.

```auto
@csrf_exempt
def test_login(request: HttpRequest):
    if request.method == "POST":
        data = request.POST
        username = data.get('username', None)
        password = data.get('password', None)
        user = authenticate(request,username=username,password=password)
        print(user)
        if user:
            return JsonResponse(data={"message":"User Found"})
        return JsonResponse(data={"message":"User Not Found"})

```

here is when I test in Django Shell

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/2/4/240877c2fc3e4193bf92dd76477487c66a4eb596.png)

I have followed to Django tutorial [Authenticating users](https://docs.djangoproject.com/en/5.0/topics/auth/default/#authenticating-users), everything work fine but when I go to Rest Framework, it’s not working anymore. Please help me.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 19, 2024, 10:29am UTC](https://forum.djangoproject.com/t/authenticate-return-none/32230/2 "2024-06-19T10:29:43Z")

</div>

Welcome @phutuan123vn !

Side note: Please do not post images of code, templates, error messages, or terminal output here. Copy/paste the text into the body of your post, enclosed between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

How are you registering users?

What do you get if you run the following commands in the shell?

```auto
user = User.objects.get(username="ptt1")
print(user.password)
user.check_password("tuan123vn")

```

---

<div class="post-metadata">

**Author:** ![phutuan123vn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/phutuan123vn/32/22046_2.png) [@phutuan123vn](https://forum.djangoproject.com/u/phutuan123vn)\
**Post date:** [June 19, 2024, 10:41am UTC](https://forum.djangoproject.com/t/authenticate-return-none/32230/3 "2024-06-19T10:41:25Z")

</div>

sry I think I know a error where it is. Thank you for your help, It’s remind me where I was wrong, Thank you so much

---

<div class="post-metadata">

**Author:** ![bredky](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/bredky/32/26150_2.png) [@bredky](https://forum.djangoproject.com/u/bredky)\
**Post date:** [January 7, 2025, 3:06pm UTC](https://forum.djangoproject.com/t/authenticate-return-none/32230/4 "2025-01-07T15:06:36Z")

</div>

hi what was what the error then? any help is appreciated
