Module: TcravitRubyLib::Utility

Extended by:
Utility
Included in:
Utility
Defined in:
lib/tcravit_ruby_lib/utility.rb

Overview

Contains random Ruby utility functions that don’t fit anywhere else.

Instance Method Summary collapse

Instance Method Details

#random_alphanumeric(size = 16, pronounceable = false) ⇒ String

Generate random alphanumeric passwords.

Previously this method generated passwords by shuffling characters in an array. It’s now just a wrapper for the simple-password-gen gem.

to 16 characters if not specified. Defaults to false.

Parameters:

  • size (Integer) (defaults to: 16)

    The length of the password to generate. Defaults

  • pronounceable (Boolean) (defaults to: false)

    True to generate pronounceable passwords.

Returns:

  • (String)

    The generated password.



42
43
44
45
46
47
48
# File 'lib/tcravit_ruby_lib/utility.rb', line 42

def random_alphanumeric(size=16, pronounceable=false)
  if pronounceable then
    return Password.pronounceable(size*2)[0..(size-1)]
  else
    return Password.random(size*2)[0..(size-1)]
  end
end