Module: KeePass::Password

Defined in:
lib/keepass/password.rb,
lib/keepass/password/version.rb,
lib/keepass/password/char_set.rb,
lib/keepass/password/generator.rb

Defined Under Namespace

Classes: CharSet, Generator, InvalidCharSetIDError, InvalidPatternError

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.estimate_entropy(test) ⇒ Object

Returns an entropy estimate of a password.

Parameters:

  • test (String)

    the password to test

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/keepass/password.rb', line 43

def self.estimate_entropy(test)
  chars = 0
  chars += 26 if test =~ LOWERCASE_TEST_RE
  chars += 26 if test =~ UPPERCASE_TEST_RE
  chars += 10 if test =~ DIGITS_TEST_RE
  chars += CharSet::PRINTABLE_ASCII_SPECIAL.size if test =~ SPECIAL_TEST_RE
  if chars == 0
    0
  else
    (test.size * Math.log(chars) / Math.log(2)).to_i
  end
end

.generate(pattern, options = {}) ⇒ String

Returns a generated password.

Parameters:

  • pattern (String)

    the pattern

  • options (Hash) (defaults to: {})

    the options

Options Hash (options):

  • :permute (Boolean) — default: true

    whether or not to randomly permute generated passwords

  • :remove_lookalikes (Boolean) — default: false

    whether or not to remove lookalike characters

  • :charset_mapping (Hash) — default: CharSet::DEFAULT_MAPPING

    the KeePass character set ID mapping

Returns:

  • (String)

    the new password

Raises:



18
19
20
# File 'lib/keepass/password.rb', line 18

def self.generate(pattern, options = {})
  Generator.new(pattern, options).generate
end

.validate_pattern(pattern, options = {}) ⇒ Boolean

Returns whether or not the pattern is valid.

Parameters:

  • pattern (String)

    the pattern

  • options (Hash) (defaults to: {})

    the options

Options Hash (options):

  • :permute (Boolean) — default: true

    whether or not to randomly permute generated passwords

  • :remove_lookalikes (Boolean) — default: false

    whether or not to remove lookalike characters

  • :charset_mapping (Hash) — default: CharSet::DEFAULT_MAPPING

    the KeePass character set ID mapping

Returns:

  • (Boolean)

    whether or not the pattern is valid



30
31
32
33
34
35
36
37
# File 'lib/keepass/password.rb', line 30

def self.validate_pattern(pattern, options = {})
  begin
    generate(pattern, options)
    true
  rescue InvalidPatternError
    false
  end
end