Coder’s Eye

A site about one of the three passions in my life.

Coder’s Eye header image 2

Howto Reset The Admin Password in Django

February 16th, 2007 · 8 Comments

I keep needing to do this, darn it! I leave a project for a few months, possibly push it live, and then I go back to fire up the dev server but I simply cannot remember the password I used for admin during development.

Why don’t I use my stupid-development-password? I don’t know, but this seems to happen with some regularity.

Luckily, it is trivial to fix with a few lines at the python commandline:

Deep:/opt/webapps/invisible bruce$ ./manage.py shell
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
Type "copyright", "credits" or "license" for more information.

IPython 0.7.2 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from django.contrib.auth.models import User

In [2]: users = User.objects.all()

In [3]: users
Out[3]: [<User: admin>]

In [4]: users[0].set_password('whatever');

In [5]: users[0].save()

That’s it, fire up the dev server again and your new password will get you in.

Technorati Tags: , , , , ,

Tags: Tips · Django · Python

Bookmark this article

del.icio.us:Howto Reset The Admin Password in Django digg:Howto Reset The Admin Password in Django spurl:Howto Reset The Admin Password in Django wists:Howto Reset The Admin Password in Django simpy:Howto Reset The Admin Password in Django newsvine:Howto Reset The Admin Password in Django blinklist:Howto Reset The Admin Password in Django furl:Howto Reset The Admin Password in Django reddit:Howto Reset The Admin Password in Django fark:Howto Reset The Admin Password in Django blogmarks:Howto Reset The Admin Password in Django Y!:Howto Reset The Admin Password in Django smarking:Howto Reset The Admin Password in Django magnolia:Howto Reset The Admin Password in Django segnalo:Howto Reset The Admin Password in Django gifttagging:Howto Reset The Admin Password in Django

8 responses so far ↓

  • 1 Amit Chakradeo // Apr 9, 2007 at 9:27 am

    This infact did not work for me as is. But if I get the user object by explicit username, it worked. Maybe this is a bug. I will need to do some testing and report it…

    So your example did not work, but the following worked:
    u=User.objects.get(username__exact=’admin’)
    u.set_password(’whatever’);
    u.save()

  • 2 links for 2007-07-09 « PaxoBlog // Jul 10, 2007 at 7:19 am

    […] Howto Reset The Admin Password in Django In [1]: from django.contrib.auth.models import User In [2]: users = User.objects.all() In [3]: users Out[3]: [] In [4]: users[0].set_password(’whatever’); In [5]: users[0].save() (tags: django password recovery login auth commandline python) […]

  • 3 Chris // Aug 8, 2007 at 3:48 pm

    Thank you for posting such useful information! That was easy and it worked beautifully with Django 0.96.

    I was just about ready to bust out sha1sum and replace the hash in the MySQL database, but this was much better.

  • 4 Antony C // Aug 14, 2007 at 7:40 pm

    Thank you :)

  • 5 Ben Chapman // Feb 14, 2008 at 7:20 am

    Thanks! Worked perfectly.

  • 6 Unixmonkey // Apr 18, 2008 at 9:08 am

    Saved me the hassle of firing up another django app, setting the admin password, and copying over the sha1 hash from one database to another.

    Thanks a lot.

  • 7 Ed W // May 23, 2008 at 4:25 pm

    You are a godsend! That worked and it saved my bacon.
    Well, at least it saved me from having to painfully re-install
    the app. (Installing the app was PAINFUL.)

  • 8 Gerard // Aug 15, 2008 at 7:07 am

    Cudo’s!!!!

    Is this useful or what! I mean am I stupid or what .. ;-)

    Regards,

    Gerard

Leave a Comment