module Devise::Models::Stretchable
Public Class Methods
required_fields(klass)
click to toggle source
# File lib/devise/async/stretch/model.rb, line 12 def self.required_fields(klass) if Devise::Async::Stretch.enabled klass.authentication_keys else [:encrypted_password] + klass.authentication_keys end end
Public Instance Methods
authenticatable_salt()
click to toggle source
This is used in the session, used to verify if the password has changed
# File lib/devise/async/stretch/model.rb, line 27 def authenticatable_salt stretch_mark if stretch_mark end
bcrypt(password, stretches=nil)
click to toggle source
Our own bcrypt mehtod which supports arbitrary stretches
# File lib/devise/async/stretch/model.rb, line 21 def bcrypt(password, stretches=nil) stretches ||= self.class.stretches ::BCrypt::Password.create("#{password}#{self.class.pepper}", cost: stretches).to_s end
Protected Instance Methods
enqueue_stretch_worker()
click to toggle source
# File lib/devise/async/stretch/model.rb, line 33 def enqueue_stretch_worker Devise::Async::Stretch::Worker.enqueue(self.class.name, id, @password) unless @password.nil? @password = nil end
password_digest(password)
click to toggle source
Digests the password using bcrypt. Custom encryption should override this method to apply their own algorithm.
See github.com/plataformatec/devise-encryptable for examples of other encryption engines.
Calls superclass method
# File lib/devise/async/stretch/model.rb, line 47 def password_digest(password) if Devise::Async::Stretch.enabled stretch = Devise::Async::Stretch.intermediate_stretch bcrypt(password, stretch) else super end end
update_stretch_mark()
click to toggle source
# File lib/devise/async/stretch/model.rb, line 38 def update_stretch_mark self[:stretch_mark] = SecureRandom.hex(15)[0,29] unless @password.blank? end