Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. post "/password_reset" do
  2. user = User.first(:email => params[:email], :temp_password => params[:temp_password])
  3. if dealer != nil then
  4. password_salt = BCrypt::Engine.generate_salt
  5. password_hash = BCrypt::Engine.hash_secret(params[:password], password_salt)
  6. user.set(:password_hash => password_hash)
  7. user.set(:password_salt => password_salt)
  8. end
  9. end
  10.  
  11. post "/auth" do
  12. @user = User.first(:email => params[:email])
  13. @user_hash = BCrypt::Password.new(@user.password_hash) #because the password_hash is stored in the db as a string, I cast it as a BCrypt::Password for comparison
  14. if @user_hash == BCrypt::Engine.hash_secret(params[:password], @user.password_salt.to_s) then
  15. auth = true
  16. else
  17. auth = false
  18. end
  19. end
  20.  
  21. if @user_hash == BCrypt::Engine.hash_secret(params[:password], @user.password_salt.to_s)
  22.  
  23. password_salt = BCrypt::Engine.generate_salt
  24. password_hash = BCrypt::Engine.hash_secret("s3kr1t!", password_salt)
  25.  
  26. puts password_salt
  27. puts password_hash
  28.  
  29. post "/password_reset" do
  30. user = User.first(:email => params[:email], :temp_password => params[:temp_password])
  31. if dealer != nil then
  32. password_hash = BCrypt::Password.create(params[:password])
  33. user.set(:password_hash => password_hash) # no need to store the salt separately in the database
  34. end
  35. end
  36.  
  37. post "/auth" do
  38. @user = User.first(:email => params[:email])
  39. @user_hash = BCrypt::Password.new(@user.password_hash)
  40. if @user_hash == params[:password] then # overridden == method performs hashing for us
  41. auth = true
  42. else
  43. auth = false
  44. end
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement