Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. user_controller
  2.  
  3. def reset_password
  4. @user = User.find_by_password_salt(params[:temppass])
  5. if @user.blank?
  6. flash[:notice] = "Temporary password incorrect. Please try again."
  7. redirect_to :action => "recover_password", :layout =>"schools"
  8. else
  9. @user.password = params[:password]
  10. flash[:notice] = "Hashed: #{@user.password_hash}, Salt: #{@user.password_salt}"
  11. if @user.save
  12. flash[:notice] = "Your new password has been registered."
  13. redirect_to :controller => session[:intended_controller], :action => session[:intended_action]
  14. else
  15. flash[:notice] = "For some reason, your new password didn't get saved."
  16. redirect_to :action => "recover_password", :layout => "schools"
  17. end
  18. end
  19. end
  20.  
  21.  
  22. user.rb
  23.  
  24. require 'digest/sha2'
  25.  
  26. class User < ActiveRecord::Base
  27. validates_uniqueness_of :email
  28. validates_length_of :password, :within => 6..20
  29. validates_presence_of :email, :password, :name_given_en, :name_family_en
  30. validates_format_of :email, :with => /^([^@\s] )@((?:[-a-z0-9] \.) [a-z]{2,})$/i,
  31. :message => "Invalid email"
  32.  
  33. def password=(pass)
  34. salt = [Array.new(6){rand(256).chr}.join].pack("m").chomp
  35. self.password_salt, self.password_hash = salt, Digest::SHA256.hexdigest(pass salt)
  36. end
  37.  
  38. end
  39.  
  40. error message: undefined method `password' for #<User:0x337c540>
  41.  
  42. BUT: session dump shows:
  43.  
  44. ---
  45. flash: !map:ActionController::Flash::FlashHash
  46. :notice: "Hashed: 98dfa4512cc1746d2dccf3e2aa69cd6be3778c89c5b2e4364dc65a8fd46a9ed7, Salt: dgIi736z"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement