I am using require ''digest/sha1'' to encrypt my password and save into database. During login it is showing the following error- undefined local variable or method `encrypted_password'' for #<Signin:0x992c990 code: before_save :encrypt_password def has_password?(submitted_password) encrypted_password == encrypt(submitted_password) end private def encrypt_password self.salt = make_salt unless has_password?(password) self.encrypted_password = encrypt(password) end def encrypt(string) secure_hash("#{salt}--#{string}") end def make_salt secure_hash("#{Time.now.utc}--#{password}") end def secure_hash(string) Digest::SHA2.hexdigest(string) end Please help me dis ! -- 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.
you are not declared ''encrypted_password'''' variable. so first declared that variable in model and use it. On Sat, Jan 28, 2012 at 1:15 PM, uma ya <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am using require ''digest/sha1'' to encrypt my password and save into > database. During login it is showing the following error- > > undefined local variable or method `encrypted_password'' for > #<Signin:0x992c990 > > code: > > before_save :encrypt_password > > def has_password?(submitted_password) > encrypted_password == encrypt(submitted_password) > end > > private > > def encrypt_password > self.salt = make_salt unless has_password?(password) > self.encrypted_password = encrypt(password) > end > > def encrypt(string) > secure_hash("#{salt}--#{string}") > end > > def make_salt > secure_hash("#{Time.now.utc}--#{password}") > end > > def secure_hash(string) > Digest::SHA2.hexdigest(string) > end > > > > Please help me dis ! > > -- > 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. > >-- 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 28 January 2012 07:45, uma ya <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am using require ''digest/sha1'' to encrypt my password and save into > database. During login it is showing the following error- > > undefined local variable or method `encrypted_password'' for > #<Signin:0x992c990You have tried to access a method encrypted_password on the Signin class. Either the signins table does not have a column of that name, or you are calling encrypted_password on the wrong class type. Colin> > code: > > before_save :encrypt_password > > def has_password?(submitted_password) > encrypted_password == encrypt(submitted_password) > end > > private > > def encrypt_password > self.salt = make_salt unless has_password?(password) > self.encrypted_password = encrypt(password) > end > > def encrypt(string) > secure_hash("#{salt}--#{string}") > end > > def make_salt > secure_hash("#{Time.now.utc}--#{password}") > end > > def secure_hash(string) > Digest::SHA2.hexdigest(string) > end > > > > Please help me dis ! > > -- > 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. >-- gplus.to/clanlaw -- 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.
i think you should read this link for this problem :- http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-two#sec:secure_passwords On Sat, Jan 28, 2012 at 2:21 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 28 January 2012 07:45, uma ya <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > I am using require ''digest/sha1'' to encrypt my password and save into > > database. During login it is showing the following error- > > > > undefined local variable or method `encrypted_password'' for > > #<Signin:0x992c990 > > You have tried to access a method encrypted_password on the Signin > class. Either the signins table does not have a column of that name, > or you are calling encrypted_password on the wrong class type. > > Colin > > > > > code: > > > > before_save :encrypt_password > > > > def has_password?(submitted_password) > > encrypted_password == encrypt(submitted_password) > > end > > > > private > > > > def encrypt_password > > self.salt = make_salt unless has_password?(password) > > self.encrypted_password = encrypt(password) > > end > > > > def encrypt(string) > > secure_hash("#{salt}--#{string}") > > end > > > > def make_salt > > secure_hash("#{Time.now.utc}--#{password}") > > end > > > > def secure_hash(string) > > Digest::SHA2.hexdigest(string) > > end > > > > > > > > Please help me dis ! > > > > -- > > 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. > > > > > > -- > gplus.to/clanlaw > > -- > 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. > >-- 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.