Sha256: 879b24947db0a322934caec7b61e7f6e689df56f42862811f5585ca77a77b419

Contents?: true

Size: 844 Bytes

Versions: 5

Compression:

Stored size: 844 Bytes

Contents

require "digest/md5"

module QuickSearch::Auth
  extend ActiveSupport::Concern

  SALT01 = SecureRandom.hex(512)
  SALT02 = SecureRandom.hex(512)
  REALM = "Please enter the username and password to access this page"
  USERS = {"#{QuickSearch::Engine::APP_CONFIG['user']}" => Digest::MD5.hexdigest(["#{QuickSearch::Engine::APP_CONFIG['user']}",REALM,"#{QuickSearch::Engine::APP_CONFIG['password']}"].join(":"))}
  SALTY = SALT01 + Digest::MD5.hexdigest(["#{QuickSearch::Engine::APP_CONFIG['user']}",REALM,"#{QuickSearch::Engine::APP_CONFIG['password']}"].join(":")) + SALT02

  def auth
    authenticate_or_request_with_http_digest(REALM) do |username|
      unless SALT01.blank? or SALT02.blank? or USERS[username].blank?
        if SALT01 + USERS[username] + SALT02 == SALTY
          USERS[username]
        end
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
quick_search-core-0.2.0 app/controllers/concerns/quick_search/auth.rb
quick_search-core-0.1.1 app/controllers/concerns/quick_search/auth.rb
quick_search-core-0.1.0 app/controllers/concerns/quick_search/auth.rb
quick_search-core-0.0.1 app/controllers/concerns/quick_search/auth.rb
quick_search-core-0.0.1.test app/controllers/concerns/quick_search/auth.rb