Skip to content

Commit

Permalink
Fix for potential remember me token collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Ferris committed Oct 21, 2009
1 parent 5f13fcf commit 536828c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/clearance/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def authenticated?(password)
# :expires => 1.year.from_now.utc
# }
def remember_me!
self.remember_token = encrypt("--#{Time.now.utc}--#{password}--")
self.remember_token = encrypt("--#{Time.now.utc}--#{password}--#{id}--")
save(false)
end

Expand Down
16 changes: 16 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ def @user.initialize_salt; end
end
end

should "not generate the same remember token for users with the same password at the same time" do
password = 'secret'
first_user = Factory(:email_confirmed_user,
:password => password,
:password_confirmation => password)
second_user = Factory(:email_confirmed_user,
:password => password,
:password_confirmation => password)

Time.stubs(:now => Time.now)
first_user.remember_me!
second_user.remember_me!

assert_not_equal first_user.remember_token, second_user.remember_token
end

# recovering forgotten password

context "An email confirmed user" do
Expand Down

0 comments on commit 536828c

Please sign in to comment.