Module: XKPassword

Defined in:
lib/xkpassword.rb,
lib/xkpassword/cli.rb,
lib/xkpassword/version.rb,
lib/xkpassword/config_file.rb

Defined Under Namespace

Classes: CLI, ConfigFile, Generator, Store, Words

Constant Summary collapse

VERSION =
'0.6.0'

Class Method Summary collapse

Class Method Details

.generate(options = nil) ⇒ Object

Generates a random password by intializing a ‘XKPassword::Generator` instance. This accepts argumennts identcal to the above class.

If you are to generate multiple passwords (batch process lets say), you might as well directly use the ‘XKPassword::Generator` class as it will be faster since it will only need to load the dictionary once.

Presets provide named defaults for common password styles, and any explicit options passed to this method override the selected preset.

Examples:

Generate with the default preset

XKPassword.generate

Generate with a preset and override one of its defaults

XKPassword.generate(preset: :apple_id, separator: '.')

Parameters:

  • options (Hash) (defaults to: nil)

    The options to populate a generator

Options Hash (options):

  • :preset (String, Symbol)

    The preset to use. Supports ‘:xkcd`, `:web32`, `:wifi`, `:security`, and `:apple_id`. Defaults to `:xkcd`.

    • ‘:xkcd` uses 4 words of 4..8 letters joined by `-`

    • ‘:web32` uses 4 words of 4..5 letters joined by `-`

    • ‘:wifi` uses 6 words of 4..8 letters joined by `-`

    • ‘:security` uses 6 lowercase words of 4..8 letters joined by spaces

    • ‘:apple_id` uses 3 words of 4..7 letters joined by `-`

  • :words (Integer)

    The number of words to include in the generated password

  • :separator (String)

    The separator symbol to use joining words used in password

  • :min_length (Integer)

    The minimum length of a word to be used in the process

  • :max_length (Integer)

    The maximum length of a word to be used in the process

  • :case_transform (String, Symbol)

    The transform to apply to every generated word



33
34
35
36
# File 'lib/xkpassword.rb', line 33

def self.generate(options = nil)
  generator = XKPassword::Generator.new
  generator.generate(options)
end