Module: Devise::Models::Encryptable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/encryptable.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#authenticatable_saltObject



33
34
35
# File 'lib/devise/models/encryptable.rb', line 33

def authenticatable_salt
  self.password_salt
end

#password=(new_password) ⇒ Object

Generates password salt.



28
29
30
31
# File 'lib/devise/models/encryptable.rb', line 28

def password=(new_password)
  self.password_salt = self.class.password_salt if new_password.present?
  super
end

#valid_password?(incoming_password) ⇒ Boolean

Verifies whether an incoming_password (ie from sign in) is the user password.

Returns:

  • (Boolean)


38
39
40
# File 'lib/devise/models/encryptable.rb', line 38

def valid_password?(incoming_password)
  Devise.secure_compare(password_digest(incoming_password), self.encrypted_password)
end