How to recover Django users password after migrating project to a different server

I migrated my Django project to a different server, so I figured that the database is the most important thing on the server since my code is on GitHub and my media files on S3 bucket. So I made a backup of the database as an SQL dump.

I setup my project, restored the database, configure my domain etc. and everything seems like nothing changed (works well). Then I tried to login but it says incorrect password. I'm thinking the way Django hash the password has changed which makes it not match the hash on the database. Every data on the database is up to date.

How can I recover the password of the users and what are best practice methods to midrate successfully? I don't have access to the old server anymore.

just rest your password with Django sheel

Go in terminal where manage.py is located And follow the steps below This command will enable shell for you

python manage.py shell

you can access user model with calling get_user_model()

>>> from django.contrib.auth import get_user_model

In this example, my username is admin and new password is 1234 so just replace you username with admin and your password with 1234

>>> user = get_user_model().objects.get(username="admin")
>>> user.set_password("1234")
>>> user.save()
>>> exit()

and now you can login with new password

Back to Top