Module: SonicPass

Defined in:
lib/sonic_pass.rb,
lib/sonic_pass/version.rb

Overview

Strong password generator.

Generates strong

Constant Summary collapse

ALPHANUMERIC_CHARSETS =
Array('A'..'Z') + Array('a'..'z') + Array('0'..'9')
SPECIAL_CHARSETS =
%w[! @ # $ % ^ & * ( ) - _ = + { } [ ] | : ; " ' < > ? , . /].freeze
CHARSETS =
ALPHANUMERIC_CHARSETS + SPECIAL_CHARSETS
VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.generate(length = 12, count = 1) ⇒ Array<String>

Combine them into a single charset if needed

Parameters:

  • length (Integer) (defaults to: 12)

    The length of the password to be generated. Defaults to 12.

  • count (Integer) (defaults to: 1)

    The number of passwords to generate. Defaults to 1.

Returns:

  • (Array<String>)

    An array of strong passwords of the specified length.



22
23
24
25
26
# File 'lib/sonic_pass.rb', line 22

def self.generate(length = 12, count = 1)
  passwords = Array.new(count) { (Array.new(length) { CHARSETS.sample }).join }

  count == 1 ? passwords[0] : passwords
end