# Remember Me login capability

**URL:** <https://www.ruby-forum.com/t/remember-me-login-capability/155517>\
**Category:** Rails\
**Created:** [December 12, 2008, 8:46pm UTC](https://www.ruby-forum.com/t/remember-me-login-capability/155517 "2008-12-12T20:46:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 12, 2008, 8:46pm UTC](https://www.ruby-forum.com/t/remember-me-login-capability/155517/1 "2008-12-12T20:46:35Z")

</div>

I have a two part question.

First just wondering if anyone out there has any good Remember Me login  
coding example or tutorials? I found one that is a couple years old and  
it seems like if should work for a rails 2.0 application but I won’t  
know until I try.

Second, the code example that I did find and am intergrating has a  
couple lines that are just confusing. In this example the user logins  
and if the remember me check box is checked this bit of code is  
executed:

# Controller code for login

@session[:user].remember\_me  
cookies[:auth\_token] = { :value =\> @session[:user].remember\_token ,  
:expires =\>  
@session[:user].remember\_token\_expires }

Then, theoretically you close down the browser and the next time you  
open it and navigate to my website you should be automatically logged  
in.

The issue that I have - and I think this is because I am not  
understanding the ruby code - is, in the remember\_me method of the User  
model I have this bit of code:

self.remember\_token = Digest::SHA1.hexdigest("#{salt}–#{self.email}–#  
{self.remember\_token\_expires}")

and this bit of code in the ApplicationController

user = User.find\_by\_remember\_token(cookies[:auth\_token])

When I save the value for the remember\_token I don’t see how I am going  
to be able to find that value in the database with the  
find\_by\_remember\_token because of the odd syntax used in the hexdigest  
method.

If the cookie has has a :value =\> ‘…’ and a :expires =\> ‘…’, how is  
the find\_by\_remember\_token going to work when the remember\_token is  
encrypted by saying  
“#{salt}–#{self.email}–#{self.remember\_token\_expires}”? It just  
doesn’t seem to me that the encrypted info and the cookie would be the  
same in the end and that I would therefore not be able to find anything  
by the User.find\_by\_remember\_token.

Not sure if this makes sense, I just didn’t want to get to far into this  
project without fully understanding what is going on. Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 12, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/remember-me-login-capability/155517/2 "2008-12-12T23:00:20Z")

</div>

Theres a good example of the code you’re looking for on the Railsspace  
site. The URL is : [http://www.railsspace.com/book/chapter7](http://www.railsspace.com/book/chapter7)

On Dec 12, 7:46 pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [December 12, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/remember-me-login-capability/155517/3 "2008-12-12T23:41:07Z")

</div>

Shockmeister wrote:

> Theres a good example of the code you’re looking for on the Railsspace  
> site. The URL is : [http://www.railsspace.com/book/chapter7](http://www.railsspace.com/book/chapter7)
> 
> On Dec 12, 7:46ï¿½pm, Shandy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> I’m pretty sure that  
> “restful\_authentication”:[http://github.com/technoweenie/restful-authentication/tree](http://github.com/technoweenie/restful-authentication/tree)  
> has that feature as well. You might look to see how it implements it.
