Forgot Django admin password? Reset it on the command line.

Cole Whitelaw | Jan 28, 2009 min read

Just a quick post. Was just rerouting some of my django stuff so I can hang a test site that I was working on from a new domain and realised that I’d forgotten my admin password doh!

So instead of farting around hashing a replacement and putting it in the database I thought I’d have a go on the python command line, so here it is:

`

from django.contrib.auth.models import User`

# Grab all users and output`

userlist = User.objects.all()
userlist
[< User:yourusername >]`

# Refer to your required user by index and set new password
>>> userlist[0].set_password('newpasswd')

# Then save it
>>> userlist[0].save()

All done!