Home > front end >  How can I log a user in without password in django?
How can I log a user in without password in django?

Time:08-03

I am trying to log a user in and I currently only know the user's email but I know for a fact that it's the correct user. The user has created a password and this is not a log in page.

So the question is how do I log the user in without the password.

I currently log people in using this:

user = authenticate(email=email,password=password)
if user is not None:
    login(request, user)
else:
    #do something

but I want to do something like this:

user = authenticate(email=email)
if user is not None:
    login(request, user)
else:
    #do something

Is this possible?

CodePudding user response:

login takes a User object, you do not have to call authenticate to retrieve the user if you really don't want to validate the user

user = User.objects.get(email=email)
login(request, user)
  • Related