Guest User

Untitled

a guest
Jan 23rd, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. # Schema: User(name:string, password_digest:string, password_salt:string)
  2. class User < ActiveRecord::Base
  3. has_secure_password
  4. end
  5.  
  6. user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
  7. user.save # => false, password required
  8. user.password = "mUc3m00RsqyRe"
  9. user.save # => false, confirmation doesn't match
  10. user.password_confirmation = "mUc3m00RsqyRe"
  11. user.save # => true
  12. user.authenticate("notright") # => false
  13. user.authenticate("mUc3m00RsqyRe") # => user
  14. User.find_by_name("david").try(:authenticate, "notright") # => nil
  15. User.find_by_name("david").try(:authenticate, "mUc3m00RsqyRe") # => user
Add Comment
Please, Sign In to add comment