File: pw_hash.rb

package info (click to toggle)
puppet-module-puppetlabs-apache 12.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,664 kB
  • sloc: ruby: 275; sh: 32; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

# @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, it's the
# most secure format supported by the most platforms.
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