2015-06-20 34 views

回答

1

制定內部使用Bcrypt寶石做加密。 Bcrypt

class User < ActiveRecord::Base 
    before_save :encrypt_password 
    validates_confirmation_of :password 
    validates_presence_of :password, :on => :create 

    def encrypt_password 
    if password.present? 
     self.password_salt = BCrypt::Engine.generate_salt 
     self.password_hash = BCrypt::Engine.hash_secret(password,password_salt) 
    end 
    end 
end 

試試這個。