Class: Dgen::PassGen

Inherits:
Object
  • Object
show all
Defined in:
lib/dgen/passgen.rb

Overview

PassGen

Author

Dick Davis

Copyright

Copyright 2015-2018 Dick Davis

License

GNU Public License 3

Generates secure diceware passphrases.

The algorithm used to generate passwords is the Diceware method, developed by Arnold Reinhold.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n_words, n_chars) ⇒ PassGen

Initializes a PassGen instance



41
42
43
44
45
46
47
48
49
# File 'lib/dgen/passgen.rb', line 41

def initialize(n_words, n_chars)
  @n_words = n_words
  @n_chars = n_chars
  path = File.expand_path(File.join(File.dirname(__FILE__),
                                    '..',
                                    'assets',
                                    'word-list.txt'))
  @word_list = File.new(path, 'r')
end

Instance Attribute Details

#n_charsObject (readonly)

Minimum character length of passphrase.



35
36
37
# File 'lib/dgen/passgen.rb', line 35

def n_chars
  @n_chars
end

#n_wordsObject (readonly)

Number of words to use in passphrase.



33
34
35
# File 'lib/dgen/passgen.rb', line 33

def n_words
  @n_words
end

#word_listObject (readonly)

File containing the list of words to select words from.



37
38
39
# File 'lib/dgen/passgen.rb', line 37

def word_list
  @word_list
end

Instance Method Details

#batch(n_pass) ⇒ Object

Produces and displays multiple passphrases.



59
60
61
62
63
64
65
# File 'lib/dgen/passgen.rb', line 59

def batch(n_pass)
  phrases = []
  n_pass.times do
    phrases.push(Dgen::Diceware.make_phrase(@n_words, @n_chars, @word_list))
  end
  phrases
end

#singleObject

Produces and displays a single passphrase.



53
54
55
# File 'lib/dgen/passgen.rb', line 53

def single
  Dgen::Diceware.make_phrase(@n_words, @n_chars, @word_list)
end