Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Last active August 29, 2015 14:01
Show Gist options
  • Save ChengLong/889363c6925ebbe72884 to your computer and use it in GitHub Desktop.
Save ChengLong/889363c6925ebbe72884 to your computer and use it in GitHub Desktop.
Simple User Model with bcrypt
require 'bcrypt'
class User < ActiveRecord::Base
include BCrypt
def password
@password ||= Password.new(password_hash)
end
def password=(new_password)
@password = Password.create(new_password)
self.password_hash = @password
end
def self.authenticate(email, password)
user = User.find_by_email(email)
return user if user && user.password == password
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment