Sha256: 8b6228f52f5ac9332f579f25e64d70853f0116be515919cbf1025ecb60438c10

Contents?: true

Size: 998 Bytes

Versions: 20

Compression:

Stored size: 998 Bytes

Contents

module Entrance

  module Ciphers

    module SHA1
      require 'digest/sha1'

      JOIN_STRING = '--'

      def self.match?(stored, given, salt = nil)
        stored === encrypt(given, salt)
      end

      # same logic as restful authentication
      def self.encrypt(password, salt)
        digest = Entrance.config.secret
        raise "Secret not set!" if digest.nil? or digest.strip == ''

        Entrance.config.stretches.times do
          str = [digest, salt, password, Entrance.config.secret].join(JOIN_STRING)
          digest = Digest::SHA1.hexdigest(str)
        end

        digest
      end

    end

    module BCrypt
      require 'bcrypt'

      # https://github.com/codahale/bcrypt-ruby
      def self.match?(stored, given, salt = nil)
        ::BCrypt::Password.new(stored) == given
        # ::BCrypt::Password.new(stored) == encrypt(given)
      end

      def self.encrypt(password, salt = nil)
        ::BCrypt::Password.create(password)
      end

    end

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
entrance-0.6.4 lib/entrance/ciphers.rb
entrance-0.6.3 lib/entrance/ciphers.rb
entrance-0.6.2 lib/entrance/ciphers.rb
entrance-0.6.1 lib/entrance/ciphers.rb
entrance-0.6.0 lib/entrance/ciphers.rb
entrance-0.5.3 lib/entrance/ciphers.rb
entrance-0.5.2 lib/entrance/ciphers.rb
entrance-0.5.1 lib/entrance/ciphers.rb
entrance-0.5.0 lib/entrance/ciphers.rb
entrance-0.4.8 lib/entrance/ciphers.rb
entrance-0.4.7 lib/entrance/ciphers.rb
entrance-0.4.6 lib/entrance/ciphers.rb
entrance-0.4.5 lib/entrance/ciphers.rb
entrance-0.4.4 lib/entrance/ciphers.rb
entrance-0.4.3 lib/entrance/ciphers.rb
entrance-0.4.2 lib/entrance/ciphers.rb
entrance-0.4.1 lib/entrance/ciphers.rb
entrance-0.4.0 lib/entrance/ciphers.rb
entrance-0.3.4 lib/entrance/ciphers.rb
entrance-0.3.3 lib/entrance/ciphers.rb