Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4035266
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:04:34+00:00 2026-05-20T12:04:34+00:00

I have a profile model I use to supplement the built in User model.

  • 0

I have a profile model I use to supplement the built in User model. I’ve made a function to reset the password of a user as follows:

def _reset_password(self):
    import random, string
    password = ''.join(random.choice(string.letters+string.digits) for i in range(10))
    u = self.user
    u.set_password(password)
    u.save()
    print u.check_password(password)
    return password

The heart of my problem can be summed up in three lines.

>>> p = Profile.objects.all()[0]
>>> u = User.objects.get(profile = p)
>>> u.check_password(p._reset_password())
True
False
>>>

It prints True because the check_password attempt in _reset_password is successful. It then prints False because the reset password somehow didn’t stick. And now again a bit more slowly for emphasis.

>>> password = p._reset_password()
True
>>> password
'uvb9SdPOwr'
>>> u.check_password(password)
False
>>> u.set_password(password)
>>> u.save()
>>> u.check_password(password)
True
>>>

Any thoughts? I’ve seriously run out of ideas. I know there must be something wrong but I can’t see it for the life of me. I know computers are deterministic and all, but this very clearly looks to me like the lines of code producing different effects.

Solution:

As miku said, my user was stale. But that error was in my command line test, not the actual model code. The location of the real (and exact same) problem was in the view:

p = u.profile
p._reset_password() #fail
u.blah = 'foo'
u.save() # u has old password, saving undoes line 2
p._reset_password() # this one takes because the stale u is never saved again
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:04:35+00:00Added an answer on May 20, 2026 at 12:04 pm

    I haven’t tested this, but it seems that your user object u is stale, because you retrieved it before you actually change the password. Try to

    u = User.objects.get(profile = p)
    

    after you reset the password and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user and a profile model. One user can have many profiles.
I have an app that makes use of 'django-registration' a custom built model named
I have a user model (sql table) that has_one : profile. profiles have user_id
I have a DLL that I want to profile.. I tried to use Very
I have a database that hold's a user's optional profile. In the profile I
Given these two models: class Profile(models.Model): user = models.ForeignKey(User, unique=True, verbose_name=_('user')) about = models.TextField(_('about'),
If I have a maven profile activated by the presence of a property, how
Anyone have experience with adding a ReSharper profile to the VS2008 solution and share
Most of my users have email addresses associated with their profile in /etc/passwd .
How do Window's programmers profile their native C++ code? On Unix/Linux you have gprof

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.