Guest User

Untitled

a guest
Feb 19th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. ## User model
  2. def self.encrypt_password(password, salt)
  3. string_to_hash = password + 'e8fa752f318b2bb039a5ded' + salt
  4. Digest::SHA1.hexdigest(string_to_hash)
  5. end
  6.  
  7. ## User controller
  8. def new
  9. @user = User.new(params[:user])
  10. if request.post? and @user.save
  11. breakpoint
  12. #...
  13. end
  14. end
  15.  
  16. ## Breakpoint commands
  17. # (Username: michael2)
  18. # (Password: testpass)
  19.  
  20. irb(#<UserController:0x37bbc90>):005:0> @user
  21. => #<User:0x3798410 @attributes={"created_on"=>Wed Jun 07 14:42:30 Central Standard Time 2006, "salt
  22. "=>"291476560.761974007124081", "name"=>"michael2", "hashed_password"=>"1a98cd33b9aed292c4735dee69ba
  23. 72a7ba7f7060", "id"=>8, "email"=>"technel@gmail.com"}, @password_confirmation="testpass", @new_recor
  24. d=false, @new_record_before_save=true, @errors=#<ActiveRecord::Errors:0x377fb88 @errors={}, @base=#<
  25. User:0x3798410 ...>>, @password="testpass">
  26. irb(#<UserController:0x37bbc90>):006:0> @user.name
  27. => "michael2"
  28. irb(#<UserController:0x37bbc90>):007:0> @user.password
  29. => "testpass"
  30. irb(#<UserController:0x37bbc90>):008:0> @user.hashed_password
  31. => "1a98cd33b9aed292c4735dee69ba72a7ba7f7060"
  32. irb(#<UserController:0x37bbc90>):009:0> @user.salt
  33. => "291476560.761974007124081"
  34. irb(#<UserController:0x37bbc90>):010:0> User.encrypt_password(@user.password, @user.salt)
  35. => "605fb78f33d8cb8779dce9848cb68544335e651e"
Add Comment
Please, Sign In to add comment