Module: ChefHelpers

Defined in:
lib/chef_helpers.rb,
lib/chef_helpers/version.rb,
lib/chef_helpers/exceptions.rb

Overview

rubocop:disable Style/Documentation

Defined Under Namespace

Modules: Exceptions

Constant Summary collapse

VERSION =
'0.1.1'

Instance Method Summary collapse

Instance Method Details

#encrypt_password(password, hash_algo = :sha512) ⇒ String

Returns an encrypted, salted password hash for use in /etc/shadow and by the Chef user resource.

Parameters:

  • password (String)

    the password to encrypt.

  • hash_algo (Symbol) (defaults to: :sha512)

    a symbol identifying the hashing algorithm to use. Valid options are:

    :sha512
    :sha256
    :md5
    :des
    

Returns:

  • (String)

    the encrypted, salted password hash.

Raises:

  • (InvalidPasswordError)

    if the generated hash does not match the password that was passed into the method.



23
24
25
26
27
# File 'lib/chef_helpers.rb', line 23

def encrypt_password(password, hash_algo = :sha512)
  build_password(password, hash_algo).tap do |pw|
    fail InvalidPasswordError unless UnixCrypt.valid?(password, pw)
  end
end