# Memcached and Joe Hosteny's Salted Hash Login Generator

**URL:** <https://www.ruby-forum.com/t/memcached-and-joe-hostenys-salted-hash-login-generator/77747>\
**Category:** Rails\
**Created:** [March 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/memcached-and-joe-hostenys-salted-hash-login-generator/77747 "2006-03-07T10:54:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@James\_Cox](https://www.ruby-forum.com/u/James_Cox)\
**Post date:** [March 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/memcached-and-joe-hostenys-salted-hash-login-generator/77747/1 "2006-03-07T10:54:20Z")

</div>

Hey,

so - I’ve been fiddling about and fell in to use Joe’s simple-yet-  
painful SHLG (I shouldn’t complain… not at least I have time to  
produce one :)). I just recently plugged in memcache, and- it’s not  
preserving my login.

I traced the execution and it sets the output of User.authenticate (a  
user AR object) into @session[‘user’] correctly - so login works. My  
next breakpoint is in user\_system.rb where it is checking  
authentication - via a before\_filter. At this point, @session[‘user’]  
is empty - and @session.session\_id has changed.

Any idea why my session\_ids are not being preserved?

more info available on request…

## – james

James Cox,  
e: removed\_email\_address@domain.invalid w: [http://www.imajes.info/](http://www.imajes.info/)

---

<div class="post-metadata">

**Author:** ![James\_Cox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@James\_Cox](https://www.ruby-forum.com/u/James_Cox)\
**Post date:** [March 7, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/memcached-and-joe-hostenys-salted-hash-login-generator/77747/2 "2006-03-07T16:48:34Z")

</div>

On Mar 7, 2006, at 1:51 AM, James Cox wrote:

> checking authentication - via a before\_filter. At this point,  
> e: removed\_email\_address@domain.invalid w: [http://www.imajes.info/](http://www.imajes.info/)  
> James-

```
I just dealt with the exact same problem with the salted hash login.

```

You could log in fine with the user/login method but when it  
redirected you to a protected page it would fail. So I put  
logger.debug session.inspect ion the user/login method and in the  
user\_system/login\_required method that gets used in the before  
filter. The first session right after login printed to the log fine.  
But by the time it made it into the other logger message the session  
was empty.

```
Its not clear whether or not you are using mem-cached for session

```

storage or for cached-model? But this following line is what was  
messing my app up:

ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update  
( :session\_domain =\> ‘.localhost.com’)

```
You need to put that in your environment.rb. And make sure it is set

```

to the correct domain that you are testing your app on. It might be  
different for memcached sessions but the same thing applies. Afetr  
fixing this the problem went away.

Cheers-  
Ezra

---

<div class="post-metadata">

**Author:** ![James\_Cox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@James\_Cox](https://www.ruby-forum.com/u/James_Cox)\
**Post date:** [March 9, 2006, 12:31am UTC](https://www.ruby-forum.com/t/memcached-and-joe-hostenys-salted-hash-login-generator/77747/3 "2006-03-09T00:31:19Z")

</div>

Ezra Z. wrote:

> On Mar 7, 2006, at 1:51 AM, James Cox wrote:
> 
> > checking authentication - via a before\_filter. At this point,  
> > e: removed\_email\_address@domain.invalid w: [http://www.imajes.info/](http://www.imajes.info/)  
> > James-
> 
> I just dealt with the exact same problem with the salted hash login.  
> You could log in fine with the user/login method but when it  
> redirected you to a protected page it would fail. So I put  
> logger.debug session.inspect ion the user/login method and in the  
> user\_system/login\_required method that gets used in the before  
> filter. The first session right after login printed to the log fine.  
> But by the time it made it into the other logger message the session  
> was empty.
> 
> Its not clear whether or not you are using mem-cached for session  
> storage or for cached-model? But this following line is what was  
> messing my app up:
> 
> ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update  
> ( :session\_domain =\> ‘.localhost.com’)
> 
> You need to put that in your environment.rb. And make sure it is set  
> to the correct domain that you are testing your app on. It might be  
> different for memcached sessions but the same thing applies. Afetr  
> fixing this the problem went away.
> 
> Cheers-  
> Ezra

Ezra -

thanks. of course. it requires a valid domain for the session it can  
match… duh!
