Class: HTAuth::Crypt

Inherits:
Algorithm show all
Defined in:
lib/htauth/crypt.rb

Overview

Internal: The basic crypt algorithm

Constant Summary collapse

ENTRY_LENGTH =
13
ENTRY_REGEX =
%r{\A[^$:\s]{#{ENTRY_LENGTH}}\z}

Constants inherited from Algorithm

Algorithm::ARGON2, Algorithm::BCRYPT, Algorithm::CRYPT, Algorithm::DEFAULT, Algorithm::EXISTING, Algorithm::MD5, Algorithm::PLAINTEXT, Algorithm::SALT_CHARS, Algorithm::SALT_LENGTH, Algorithm::SHA1

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Algorithm

algorithm_from_field, algorithm_from_name, algorithm_name, #gen_salt, secure_compare, #to_64, #verify_password?

Methods included from DescendantTracker

#children, #find_child, #inherited

Constructor Details

#initialize(params = {}) ⇒ Crypt

Returns a new instance of Crypt.



18
19
20
21
22
23
24
# File 'lib/htauth/crypt.rb', line 18

def initialize(params = {})
  if existing = (params['existing'] || params[:existing]) then
    @salt = self.class.extract_salt_from_existing_password_field(existing)
  else
    @salt = params[:salt] || params['salt'] || gen_salt
  end
end

Class Method Details

.extract_salt_from_existing_password_field(existing) ⇒ Object



14
15
16
# File 'lib/htauth/crypt.rb', line 14

def self.extract_salt_from_existing_password_field(existing)
  existing[0,2]
end

.handles?(password_entry) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/htauth/crypt.rb', line 10

def self.handles?(password_entry)
  ENTRY_REGEX.match?(password_entry)
end

Instance Method Details

#encode(password) ⇒ Object



26
27
28
# File 'lib/htauth/crypt.rb', line 26

def encode(password)
  password.crypt(@salt)
end