Puppet Function: apache::pw_hash

Defined in:
lib/puppet/functions/apache/pw_hash.rb
Function type:
Ruby 4.x API

Summary

Hashes a password in a format suitable for htpasswd files read by apache.

Overview

apache::pw_hash(String[1] $password)String

Currently uses SHA-hashes, because although this format is considered insecure, it’s the most secure format supported by the most platforms.

Parameters:

  • password (String[1])

    The input that is to be hashed.

Returns:

  • (String)

    Returns the hash of the input that was given.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/functions/apache/pw_hash.rb', line 8

Puppet::Functions.create_function(:'apache::pw_hash') do
  # @param password
  #   The input that is to be hashed.
  #
  # @return
  #   Returns the hash of the input that was given.
  dispatch :apache_pw_hash do
    required_param 'String[1]', :password
    return_type 'String'
  end

  def apache_pw_hash(password)
    require 'base64'
    '{SHA}' + Base64.strict_encode64(Digest::SHA1.digest(password))
  end
end