Ben
Ben

Reputation: 2557

How can I update a Django user's password from inside Postgres?

I'd like to reset a user password, but only have access to the Postgres database. Dropping in plaintext doesn't work, and the hashing process for Django appears to be too complex to replicate.

Any thoughts?

Upvotes: 1

Views: 1176

Answers (3)

D. Andrei
D. Andrei

Reputation: 141

You can get a backup on your dev machine and create a new superuser by doing:

python3 manage.py createsuperuser --email <email> --username <username>

Then you will be able to login and change passwords as you like. Maybe restore the backup afterwards.

I know this does not answer your question because you also need to have access to the repo, but maybe it helps someone else.

Upvotes: 0

Mr.k1n1
Mr.k1n1

Reputation: 74

    from django.contrib.auth.models import User  

    u = User.objects.get(username="username")
    u.set_password("New Password")
    u.save()

Upvotes: -1

jjanes
jjanes

Reputation: 44353

the hashing process for Django appears to be too complex to replicate

If this is true, then I think the definitive answer is "You can't change it from inside PostgreSQL".

Upvotes: 0

Related Questions