Puppet Function: mysql::password

Defined in:
lib/puppet/functions/mysql/password.rb
Function type:
Ruby 4.x API

Overview

mysql::password(String $password)String

Hash a string as mysql’s “PASSWORD()” function would do it

Parameters:

  • password (String)

    Plain text password.

Returns:

  • (String)

    hash The mysql password hash from the clear text password.



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

Puppet::Functions.create_function(:'mysql::password') do
  # @param password
  #   Plain text password.
  #
  # @return hash
  #   The mysql password hash from the clear text password.
  #
  dispatch :password do
    required_param 'String', :password
    return_type 'String'
  end

  def password(password)
    return '' if password.empty?
    return password if %r{\*[A-F0-9]{40}$}.match?(password)
    '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(password)).upcase
  end
end