class HTAuth::Bcrypt

an implementation of the Bcrypt based encoding algorithm as used in the apache htpasswd -B option

Constants

DEFAULT_APACHE_COST

Attributes

cost[RW]

Public Class Methods

extract_cost_from_existing_password_field(existing) click to toggle source
# File lib/htauth/bcrypt.rb, line 18
def self.extract_cost_from_existing_password_field(existing)
  password = ::BCrypt::Password.new(existing)
  password.cost
end
handles?(password_entry) click to toggle source
# File lib/htauth/bcrypt.rb, line 14
def self.handles?(password_entry)
  return ::BCrypt::Password.valid_hash?(password_entry)
end
new(params = {}) click to toggle source
# File lib/htauth/bcrypt.rb, line 23
def initialize(params = {})
  if existing = (params['existing'] || params[:existing]) then
    @cost = self.class.extract_cost_from_existing_password_field(existing)
  else
    @cost = params['cost'] || params[:cost] || DEFAULT_APACHE_COST
  end
end

Public Instance Methods

encode(password) click to toggle source
# File lib/htauth/bcrypt.rb, line 31
def encode(password)
  ::BCrypt::Password.create(password, :cost => cost)
end