Authenticate

I have been struggling with this for a while and am at a loss. I have a
form allowing current users to log in and new users to create an
account. Upon hitting the submit buttons (one for each action) a method
gets called either ‘new_user’ or ‘create_user’, both makes use of a
method in my user model called ‘authenticate’. The really weird part is
that for creating a new user authenticate works fine but not for
‘current_user’. To make things weirder, the calls are EXACTLY the same!

In method new_user:

 if request.post? and @user.save
    session[:user] = User.authenticate( params[:user][:email],

params[:user]
[:password] ).id
redirect_to :action => ‘welcome’, :id => @user.id

In current_user

if [email protected]? and User.authenticate( params[:user][:email],

params[:user]
[:password] )
session[:user] = User.authenticate( params[:user][:email],
params[:user]
[:password] ).id
flash[:notice] = “<b style = “color:red”>Worked”
redirect_to :action => ‘welcome’, :id => @user.id

Authenticate looks like:

def self.authenticate(email, password)
user = User.find(:first, :conditions => [‘upper(email) = ?’,
email.upcase])
if user.blank? ||
Digest::SHA256.hexdigest(password+user.password_salt)
!= user.password_hash
#raise “Unknown userid or password”
else
user
end
end

Erro message when current_user method is called:

can’t convert nil into String

#{RAILS_ROOT}/app/models/user.rb:18:in +' #{RAILS_ROOT}/app/models/user.rb:18:inauthenticate’
#{RAILS_ROOT}/app/controllers/music_controller.rb:64:in `current_user’

Now, given the fact that the call to new user works without throwing any
errors I’m amusing (aparently wrongfully) that the call to current_user
should work as well, especially since I can see that all the correct
parameters are being passed and therefore know that password is not
infact nil? Anyone have any ideas? Thanks,

-Shandy

can password_salt be nil ? Are use sure that the parameters are arriving
as params[:user][:password] and not params[:password] ?
Have you tried using rdebug to step through your code ?

Fred

Frederick C. wrote:

can password_salt be nil ? Are use sure that the parameters are arriving
as params[:user][:password] and not params[:password] ?
Have you tried using rdebug to step through your code ?

Fred

I’m sure that the parameters are arriving correctly. On the error page
that is displayed I can see that the correct password is arriving. I do
believe that the salt is not nill, but I’m not entirly sure and I’ll
have to check later.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs