Skip to content

Commit

Permalink
[1.0.X] Fixed #10265: fixed a bug when generating a password reset to…
Browse files Browse the repository at this point in the history
…ken for a user created on the same request. Thanks, crucialfelix. Backport of r10341 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10342 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed Apr 1, 2009
1 parent eb24c7f commit 647ff3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions django/contrib/auth/tests/tokens.py
Expand Up @@ -8,6 +8,14 @@
>>> p0.check_token(u, tk1)
True
>>> u = User.objects.create_user('comebackkid', 'test3@example.com', 'testpw')
>>> p0 = PasswordResetTokenGenerator()
>>> tk1 = p0.make_token(u)
>>> reload = User.objects.get(username='comebackkid')
>>> tk2 = p0.make_token(reload)
>>> tk1 == tk2
True
Tests to ensure we can use the token after n days, but no greater.
Use a mocked version of PasswordResetTokenGenerator so we can change
the value of 'today'
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/auth/tokens.py
Expand Up @@ -52,7 +52,7 @@ def _make_token_with_timestamp(self, user, timestamp):
# We limit the hash to 20 chars to keep URL short
from django.utils.hashcompat import sha_constructor
hash = sha_constructor(settings.SECRET_KEY + unicode(user.id) +
user.password + unicode(user.last_login) +
user.password + user.last_login.strftime('%Y-%m-%d %H:%M:%S') +
unicode(timestamp)).hexdigest()[::2]
return "%s-%s" % (ts_b36, hash)

Expand Down

0 comments on commit 647ff3f

Please sign in to comment.