How to setup a Session and use its data from other classes?

I am trying to do an authentication where I have :
session[“User”] = User.authenticate(@params[“name”],
@params[“password”])

and the program continues on if the authentication is correct. Now if
later on in the session I want to access “User”'s data (using active
directory) I try to use:

if session[“User”].id == 0
//do something
else
//do something else

Now I always get id =0 so i must have set the session wrong or not at
all? Here is how i do the authentication:

if session[“User”] = User.authenticate(@params[“name”],
@params[“password”])
if session[“return_to”]
redirect_to_path(session[“return_to”])
session[“return_to”] = nil
else
redirect_to :controller => “NewController”
end
else
flash[:error] = ‘Invalid user name and/or password.’
redirect_to :action => “index”
end

I try to use session[“User”] elsewhere to get data but no good. Can
someone help? thanks!

First question is “Does your User.authenticate return a user object to
be stored in session?”

From the sparse look we have at the code, that’s where I’d be looking
first…

No, the User.authenticate does :
User.find(first,…) to check for user authentication. How do I
return the object? with this way? sorry i am bit new at this…
thanks!

it also seems the ID is 0,1 and apparently in ruby that is true/false
class… so after I set the session correctly do I just do :

if session[“User”].id == true
//do something
else
//etc…
?