Sha256: 61bdb5ec1e1b0cfed347d3d03e21e915682aa419de8404852d250e0c64a982db
Contents?: true
Size: 1.76 KB
Versions: 3
Compression:
Stored size: 1.76 KB
Contents
require 'devise/strategies/database_authenticatable' module Devise module Models # Encryptable Module adds support to several encryptors. # # == Options # # Encryptable adds the following options to devise_for: # # * +pepper+: a random string used to provide a more secure hash. # # * +encryptor+: the encryptor going to be used. By default is nil. # # == Examples # # User.find(1).valid_password?('password123') # returns true/false # module Encryptable extend ActiveSupport::Concern included do attr_reader :password, :current_password attr_accessor :password_confirmation end # Generates password salt. def password=(new_password) self.password_salt = self.class.password_salt if new_password.present? super end def authenticatable_salt self.password_salt end # Verifies whether an incoming_password (ie from sign in) is the user password. def valid_password?(incoming_password) password_digest(incoming_password) == self.encrypted_password end protected # Digests the password using the configured encryptor. def password_digest(password) if self.password_salt.present? self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper) end end module ClassMethods Devise::Models.config(self, :encryptor) # Returns the class for the configured encryptor. def encryptor_class @encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify) end def password_salt self.encryptor_class.salt(self.stretches) end end end end end
Version data entries
3 entries across 3 versions & 3 rubygems
Version | Path |
---|---|
devise-1.2.rc | lib/devise/models/encryptable.rb |
aihs_devise-1.2.rc | lib/devise/models/encryptable.rb |
gonow-devise-1.2.rc | lib/devise/models/encryptable.rb |