Puppet Function: apache_pw_hash

Defined in:
lib/puppet/parser/functions/apache_pw_hash.rb
Function type:
Ruby 3.x API

Summary

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

Overview

apache_pw_hash(Any $password)Any

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

Parameters:

  • password (Any)

    The input that is to be hashed.

Returns:

  • (Any)

    Return’s the hash of the input that was given.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/puppet/parser/functions/apache_pw_hash.rb', line 3

Puppet::Parser::Functions.newfunction(:apache_pw_hash, type: :rvalue, doc: <<-DOC
  @summary
    Hashes a password in a format suitable for htpasswd files read by apache.

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

  @param password
    The input that is to be hashed.

  @return
    Return's the hash of the input that was given.
DOC
                                     ) do |args|
  raise(Puppet::ParseError, "apache_pw_hash() wrong number of arguments. Given: #{args.size} for 1)") if args.size != 1
  raise(Puppet::ParseError, 'apache_pw_hash(): first argument must be a string') unless args[0].is_a? String
  raise(Puppet::ParseError, 'apache_pw_hash(): first argument must not be empty') if args[0].empty?

  password = args[0]
  return '{SHA}' + Base64.strict_encode64(Digest::SHA1.digest(password))
end