Devise::Models::Encryptable

Encryptable module adds support to several encryptors wrapping them in a salt and pepper mechanism to increase security.

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

Public Class Methods

required_fields(klass) click to toggle source
# File lib/devise/encryptable/model.rb, line 28
def self.required_fields(klass)
  [:password_salt]
end

Public Instance Methods

authenticatable_salt() click to toggle source

Overrides authenticatable salt to use the new password_salt column. authenticatable_salt is used by `valid_password?` and by other modules whenever there is a need for a random token based on the user password.

# File lib/devise/encryptable/model.rb, line 48
def authenticatable_salt
  self.password_salt
end
password=(new_password) click to toggle source

Generates password salt when setting the password.

# File lib/devise/encryptable/model.rb, line 33
def password=(new_password)
  self.password_salt = self.class.password_salt if new_password.present?
  super
end
valid_password?(password) click to toggle source

Validates the password considering the salt.

# File lib/devise/encryptable/model.rb, line 39
def valid_password?(password)
  return false if encrypted_password.blank?
  encryptor_class.compare(encrypted_password, password, self.class.stretches, authenticatable_salt, self.class.pepper)
end

Protected Instance Methods

encryptor_class() click to toggle source
# File lib/devise/encryptable/model.rb, line 61
def encryptor_class
  self.class.encryptor_class
end
password_digest(password) click to toggle source

Digests the password using the configured encryptor.

# File lib/devise/encryptable/model.rb, line 55
def password_digest(password)
  if password_salt.present?
    encryptor_class.digest(password, self.class.stretches, authenticatable_salt, self.class.pepper)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.