Application will not authenticate [sends alert of invalid credentials]. Using user credentials created via rake db:seed. How do I get it to authenticate? Agent Model ---------------- def Agent.authenticate(name,password) if agent = find_by_name(name) if agent.hash == encrypt_password(password,agent.salt) agent end end end SessionController ---------------------- def create if agent = Agent.authenticate(params[:name],params[:password]) session[:agent_id] = agent.id redirect_to base_url else redirect_to login_url,:alert=>"Invalid credentials" end end Attachments: http://www.ruby-forum.com/attachment/7352/agent.rb http://www.ruby-forum.com/attachment/7353/application_controller.rb http://www.ruby-forum.com/attachment/7354/sessions_controller.rb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 1 May 2012 14:00, Daniel Coston <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Application will not authenticate [sends alert of invalid credentials]. > Using user credentials created via rake db:seed. How do I get it to > authenticate?Which bit is not working? See the Rails Guide on debugging for help on how to debug your code. Colin> > Agent Model > ---------------- > > def Agent.authenticate(name,password) > if agent = find_by_name(name) > if agent.hash == encrypt_password(password,agent.salt) > agent > end > end > end > > SessionController > ---------------------- > > def create > if agent = Agent.authenticate(params[:name],params[:password]) > session[:agent_id] = agent.id > redirect_to base_url > else > redirect_to login_url,:alert=>"Invalid credentials" > end > end > > Attachments: > http://www.ruby-forum.com/attachment/7352/agent.rb > http://www.ruby-forum.com/attachment/7353/application_controller.rb > http://www.ruby-forum.com/attachment/7354/sessions_controller.rb > > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 1, 2:00 pm, Daniel Coston <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Application will not authenticate [sends alert of invalid credentials]. > Using user credentials created via rake db:seed. How do I get it to > authenticate? > > Agent Model > ---------------- > > def Agent.authenticate(name,password) > if agent = find_by_name(name) > if agent.hash == encrypt_password(password,agent.salt)Have you tried calling agent.hash ? I''d wager that that methods returns something you don''t expect, because hash is a method all ruby objects have - I suspect that you''re calling that method rather than the one that would return the value of your hash column. You can get at the attribute value via read_attribute, although I''d recommend avoiding dangerous names like that. Fred> agent > end > end > end > > SessionController > ---------------------- > > def create > if agent = Agent.authenticate(params[:name],params[:password]) > session[:agent_id] = agent.id > redirect_to base_url > else > redirect_to login_url,:alert=>"Invalid credentials" > end > end > > Attachments:http://www.ruby-forum.com/attachment/7352/agent.rbhttp://www.ruby-forum.com/attachment/7353/application_controller.rbhttp://www.ruby-forum.com/attachment/7354/sessions_controller.rb > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #1059060:> On 1 May 2012 14:00, Daniel Coston <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Application will not authenticate [sends alert of invalid credentials]. >> Using user credentials created via rake db:seed. How do I get it to >> authenticate? > > Which bit is not working? See the Rails Guide on debugging for help > on how to debug your code. > > ColinSessionsController portion not working. Will consult guide for debugging. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #1059064:> On May 1, 2:00pm, Daniel Coston <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Application will not authenticate [sends alert of invalid credentials]. >> Using user credentials created via rake db:seed. How do I get it to >> authenticate? >> >> Agent Model >> ---------------- >> >> def Agent.authenticate(name,password) >> if agent = find_by_name(name) >> if agent.hash == encrypt_password(password,agent.salt) > > Have you tried calling agent.hash ? I''d wager that that methods > returns something you don''t expect, because hash is a method all ruby > objects have - I suspect that you''re calling that method rather than > the one that would return the value of your hash column. You can get > at the attribute value via read_attribute, although I''d recommend > avoiding dangerous names like that. > > FredAppreciate your insight. Was unaware hash was inherited by all objects. Will try changing the name. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.