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
-
.estimate_entropy(test) ⇒ Object
Returns an entropy estimate of a password.
-
.generate(pattern, options = {}) ⇒ String
Returns a generated password.
-
.validate_pattern(pattern, options = {}) ⇒ Boolean
Returns whether or not the pattern is valid.
Class Method Details
.estimate_entropy(test) ⇒ Object
Returns an entropy estimate of a password.
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.
18 19 20 |
# File 'lib/keepass/password.rb', line 18 def self.generate(pattern, = {}) Generator.new(pattern, ).generate end |
.validate_pattern(pattern, options = {}) ⇒ Boolean
Returns 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, = {}) begin generate(pattern, ) true rescue InvalidPatternError false end end |