# How can I make the user login automatically after email verification?

**URL:** <https://forum.djangoproject.com/t/how-can-i-make-the-user-login-automatically-after-email-verification/17909>\
**Category:** Forms & APIs\
**Created:** [December 30, 2022, 2:00am UTC](https://forum.djangoproject.com/t/how-can-i-make-the-user-login-automatically-after-email-verification/17909 "2022-12-30T02:00:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cnr91](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/cnr91/32/24082_2.png) [@cnr91](https://forum.djangoproject.com/u/cnr91)\
**Post date:** [December 30, 2022, 2:00am UTC](https://forum.djangoproject.com/t/how-can-i-make-the-user-login-automatically-after-email-verification/17909/1 "2022-12-30T02:00:04Z")

</div>

How can I make the user login automatically after email verification?

This function works if the password is not hashed.

```auto
from django.contrib import auth

try:
    uid = urlsafe_base64_decode(uidb64).decode()
    user = Account._default_manager.get(pk=uid)
except(TypeError, ValueError, OverflowError, Account.DoesNotExist):
    user = None

userlogin = auth.authenticate(email=user.email, password=user.password)
auth.login(request, userlogin)

```

I want email confirmation from the user, so I can only use the hashed password but encrypted password does not work with this function.

Error:  
**AttributeError: ‘AnonymousUser’ object has no attribute ‘\_meta’**

Do you have any suggestion?

Thank you.

---

<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:** [December 30, 2022, 3:29am UTC](https://forum.djangoproject.com/t/how-can-i-make-the-user-login-automatically-after-email-verification/17909/2 "2022-12-30T03:29:41Z")

</div>

If you are sure that it’s a valid user clicking on that link (a really bad idea), then you can just log the user in using the [`login`](https://docs.djangoproject.com/en/4.1/topics/auth/default/#how-to-log-a-user-in) function - you don’t need to use the [`authenticate`](https://docs.djangoproject.com/en/4.1/topics/auth/default/#django.contrib.auth.authenticate) function.
