Class: Capsium::Reactor::Htpasswd

Inherits:
Object
  • Object
show all
Defined in:
lib/capsium/reactor/htpasswd.rb,
sig/capsium/reactor/htpasswd.rbs

Overview

Apache htpasswd verification (05x-authentication). Supported hash formats: bcrypt ($2a$/$2b$/$2y$), Apache apr1 MD5 and md5-crypt ($apr1$/$1$), unsalted SHA-1 (SHA), and a crypt(3) fallback for the rest (platform-dependent).

Defined Under Namespace

Modules: Md5Crypt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Htpasswd

Returns a new instance of Htpasswd.

Parameters:

  • path (String)

Raises:



91
92
93
94
95
96
# File 'lib/capsium/reactor/htpasswd.rb', line 91

def initialize(path)
  raise Error, "htpasswd file not found: #{path}" unless File.file?(path)

  @path = path
  @entries = parse(path)
end

Instance Attribute Details

#pathString (readonly)

Returns the value of attribute path.

Returns:

  • (String)


89
90
91
# File 'lib/capsium/reactor/htpasswd.rb', line 89

def path
  @path
end

Instance Method Details

#usernamesArray[String]

Returns:

  • (Array[String])


98
99
100
# File 'lib/capsium/reactor/htpasswd.rb', line 98

def usernames
  @entries.keys
end

#verify?(username, password) ⇒ Boolean

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Boolean)


102
103
104
105
106
107
# File 'lib/capsium/reactor/htpasswd.rb', line 102

def verify?(username, password)
  hash = @entries[username]
  return false unless hash

  verify_hash(hash, password)
end