Sha256: db1f985ab8992f9d47de4f21d7b654269328f1694c95283c27dc60a90fc8b3d7
Contents?: true
Size: 884 Bytes
Versions: 25
Compression:
Stored size: 884 Bytes
Contents
require 'rack' require 'webrick/httpauth/htpasswd' module TDiary module Rack module Auth class PasswordFileNotFound < StandardError; end class Basic def initialize(app, file = '.htpasswd') @authenticator = ::Rack::Auth::Basic.new(app) do |user, pass| unless File.exist?(file) raise PasswordFileNotFound.new("#{file} is not found. Please create it by htpasswd program.") end htpasswd = WEBrick::HTTPAuth::Htpasswd.new(file) crypted = htpasswd.get_passwd(nil, user, false) crypted == pass.crypt(crypted) if crypted end end def call(env) begin @authenticator.call(env) rescue PasswordFileNotFound => e [403, {"Content-Type" => "text/plain"}, [e.message]] end end end end end end # Local Variables: # mode: ruby # indent-tabs-mode: t # tab-width: 3 # ruby-indent-level: 3 # End:
Version data entries
25 entries across 25 versions & 1 rubygems