Sha256: 73482177c976b4d145892b8fd8a5a3dcb440a22772da8809a6e98e67e67e2613

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

require "digest/sha2"
require "base64"

module Devise

  # Declare encryptors length which are used in migrations.
  ENCRYPTORS_LENGTH = {
    :dovecot_ssha512 => 72
  }

  # Used to define the password encryption algorithm.
  mattr_accessor :encryptor
  @@encryptor = nil

  module Encryptable
    module Encryptors
      class DovecotSsha512
        # Generates a default password digest based on salt, pepper and the
        # incoming password.
        def self.digest(password, stretches, salt, pepper)
          digest = password #[password, salt].flatten.join('')
          stretches.times { digest = Digest::SHA512.digest(digest) }
          '{SHA512}'+ Base64.encode64(digest).chomp # + salt)
        end
        def self.compare(encrypted_password, password, stretches, salt, pepper)
          Devise.secure_compare(encrypted_password, digest(password, stretches, salt, pepper))
        end
        def self.salt(stretches)
          Devise.friendly_token[0,20]
        end
      end
    end
  end
end

#Devise.add_module(:encryptable, :model => './model')
Devise.add_module( :encryptable)

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rmails-0.2.1 config/initializers/devise_encryptable.rb
rmails-0.2.0 config/initializers/devise_encryptable.rb
rmails-0.1.6 config/initializers/devise_encryptable.rb
rmails-0.1.5 config/initializers/devise_encryptable.rb
rmails-0.1.4 config/initializers/devise_encryptable.rb
rmails-0.1.3 config/initializers/devise_encryptable.rb
rmails-0.1.2 config/initializers/devise_encryptable.rb
rmails-0.1.1 config/initializers/devise_encryptable.rb