Encryptable module adds support to several encryptors wrapping them in a salt and pepper mechanism to increase security.
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.
User.find(1).valid_password?('password123') # returns true/false
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
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
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
# File lib/devise/encryptable/model.rb, line 61 def encryptor_class self.class.encryptor_class end
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
Generated with the Darkfish Rdoc Generator 2.