On Sat, Sep 22, 2012 at 3:18 PM, Nandakumar Chandrasekhar <navanitach...@gmail.com> wrote: > Thanks Andrew but I have a requirement where I have to programmatically set > it to an unusable password based on a particular condition.
Andrew's given you the answer - it's just not clear that you've understood what the answer is. There are two ways to set a password on a user object: * Use the set_password() method on the user object. * Set the underlying password attribute directly. The set_password() method is just applying the password hashing logic and then saving the password field directly. If you want to set the hashed value -- or set an "unusable" value -- directly, you can do the same thing: >>> from django.contrib.auth.models import User, UNUSABLE_PASSWORD >>> user = User.objects.get(username='frank') >>> user.password u'sha1$911ee$25e954dc93f920c134ebaa067da7827922e474a6' >>> user.has_usable_password() True >>> user.set_password('foo') >>> user.password 'sha1$7h9Fpv6nLJt4$99f05f9b65569b617f32a448431736108e83be36' >>> user.has_usable_password() True >>> user.password = UNUSABLE_PASSWORD >>> user.save() >>> user.password '!' >>> user.has_usable_password() False Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.