xkpassword 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfed3f08e36ae1aab210348dc428cae6c010c3f8
4
- data.tar.gz: f4a354aafded3a56625438cf718e2f0b8ce95158
3
+ metadata.gz: f84da1ad0dfef6ea960bb3e03d167ede3b3a45b1
4
+ data.tar.gz: 838f02e3b6a4bb534c91bfe5fddee5168bf05d2a
5
5
  SHA512:
6
- metadata.gz: dd3a65350baf83fe693c48d06d34e682f9ef3f323e3a5649f214c7df20a80f80e2915e33cf70ae3f8cc1f0252550f26ecf5e12dfdb2d366bab2635369976c0af
7
- data.tar.gz: 66465600de579c1f7f91a7641c1d54a93ddd2284313a85c5a0779ef7fd2d5df897c2bdd7f0fb2b701ac698c08bbcd17b908d7a2713a523ff48e9b12d6f1f69f2
6
+ metadata.gz: 2fd8e2109dedce564cc2f5d254b4f9ac55da1b2aa2a385f6a2bfd1e2e349b5e75c191aab48e1f7bfb4da121c304087770d001eb68caf5f5832d30208f385ad25
7
+ data.tar.gz: 8976003191ea7e0caa2170bb334e535c91568c275b3d3cfa338d7be1353c52c0229194a2ebefb1bb8dc358c16be640f504ad9dcf40a2a0b897a73dec67ca0fc5
data/Gemfile CHANGED
@@ -4,5 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
+ gem 'yard'
7
8
  gem 'pry'
8
9
  end
data/README.md CHANGED
@@ -22,7 +22,52 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ You can use this app stand-alone in the command line or include it in any of your Ruby
26
+ applications.
27
+
28
+ ### Comamnd Line
29
+ The commandline application accepts the same collection of configuration options as would
30
+ the `XKPassword` module would. For more information use `xkpassword --help` to obtain a
31
+ full list of options.
32
+
33
+ ```bash
34
+ ~# xkpassword
35
+ ~# xkpassword --help
36
+ ```
37
+
38
+ ### Ruby Apps
39
+
40
+ ```ruby
41
+ require 'xkpassword/generator'
42
+
43
+ options = {
44
+ max_length: 8,
45
+ min_length: 4,
46
+ separator: '-',
47
+ words: 4,
48
+ }
49
+
50
+ XKPassword.generate(options)
51
+ ```
52
+
53
+ If you are generating multiple passwords at once, I recommend you use
54
+ the following as then it will only load and parse the databse once.
55
+
56
+ ```ruby
57
+ require 'xkpassword/generator'
58
+
59
+ options = {
60
+ max_length: 8,
61
+ min_length: 4,
62
+ separator: '-',
63
+ words: 4,
64
+ }
65
+
66
+ generator = XKPassword::Generator.new
67
+ generator.generate(options)
68
+
69
+ # 10.times { generator.generate(options) }
70
+ ```
26
71
 
27
72
  ## Development
28
73
 
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'artii'
5
-
6
- require 'bundler/setup'
7
- require 'xkpassword'
8
-
9
- artii = Artii::Base.new font: 'standard'
10
- message = """
11
- #{ artii.asciify('XKPassword') }
12
- by Ziyan Junaideen
13
-
14
- How many times have you changed your password just because you forgot it?
15
- Well, you are not alone. In todays security requirements, passwords need
16
- to be secure and difficult to break. Passwords need to be secure, sure,
17
- but they can also be easy to remember. Follow up this XKCD article for more
18
- information - http://xkcd.com/936/
19
-
20
- This does exactly what the picture predicts. You can use this in your Ruby
21
- applications (Ex: Rails, Sinatra) or standalone if you install the gem (as
22
- you have done here).
23
-
24
- Wish you all the best keeping things secure.
25
-
26
- Ziyan Junaideen
27
- ziyan@jdeen.com
28
-
29
- """
30
-
31
- options = {}
32
- OptionParser.new do |opts|
33
- opts.banner = "Usage: ./bin/xkpassword [options]"
34
-
35
- opts.on('-v', '--version', 'Gem version') { options[:version] = true }
36
- opts.on('-i', '--info', 'Gem info') { options[:info] = true }
37
-
38
- opts.on('--words [INTEGER]', 'Number of wrods to be used in the generated password') { |words| options[:words] = words.to_i }
39
- opts.on('--min-length [INTEGER]', 'Minimum length of a word') { |min| options[:min_length] = min.to_i }
40
- opts.on('--max-length [INTEGER]', 'Maximum length of a word') { |max| options[:max_length] = max.to_i }
41
- opts.on('--separator [STRING]', 'The separator to separate password') { |separator| options[:separator] = separator }
42
- end.parse!
43
-
44
- puts message if options[:info]
45
- puts XKPassword::VERSION if options[:version]
46
- puts XKPassword.generate(options) if !options[:info] && !options[:version]
47
-
48
-
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'artii'
5
+
6
+ require 'bundler/setup'
7
+ require 'xkpassword'
8
+
9
+ artii = Artii::Base.new font: 'standard'
10
+ message = """
11
+ #{ artii.asciify('XKPassword') }
12
+ by Ziyan Junaideen
13
+
14
+ How many times have you changed your password just because you forgot it?
15
+ Well, you are not alone. In todays security requirements, passwords need
16
+ to be secure and difficult to break. Passwords need to be secure, sure,
17
+ but they can also be easy to remember. Follow up this XKCD article for more
18
+ information - http://xkcd.com/936/
19
+
20
+ This does exactly what the picture predicts. You can use this in your Ruby
21
+ applications (Ex: Rails, Sinatra) or standalone if you install the gem (as
22
+ you have done here).
23
+
24
+ Wish you all the best keeping things secure.
25
+
26
+ Ziyan Junaideen
27
+ ziyan@jdeen.com
28
+
29
+ """
30
+
31
+ options = {}
32
+ OptionParser.new do |opts|
33
+ opts.banner = "Usage: ./exe/xkpassword [options]"
34
+
35
+ opts.on('-v', '--version', 'Gem version') { options[:version] = true }
36
+ opts.on('-i', '--info', 'Gem info') { options[:info] = true }
37
+
38
+ opts.on('--words [INTEGER]', 'Number of wrods to be used in the generated password') { |words| options[:words] = words.to_i }
39
+ opts.on('--min-length [INTEGER]', 'Minimum length of a word') { |min| options[:min_length] = min.to_i }
40
+ opts.on('--max-length [INTEGER]', 'Maximum length of a word') { |max| options[:max_length] = max.to_i }
41
+ opts.on('--separator [STRING]', 'The separator to separate password') { |separator| options[:separator] = separator }
42
+ end.parse!
43
+
44
+ puts message if options[:info]
45
+ puts XKPassword::VERSION if options[:version]
46
+ puts XKPassword.generate(options) if !options[:info] && !options[:version]
47
+
48
+
@@ -1,8 +1,22 @@
1
1
  module XKPassword
2
+
3
+ # Generates a random password by intializing a `XKPassword::Generator` instance.
4
+ # This accepts argumennts identcal to the above class.
5
+ #
6
+ # If you are to generate multiple passwords (batch process lets say), you might as well directly
7
+ # use the `XKPassword::Generator` class as it will be faster since it will only need to load
8
+ # the dictionary once.
9
+ #
10
+ # @param [Hash] options The options to populate a generator
11
+ # @option options [Integer] :words The number of words to include in the generated password
12
+ # @option options [String] :separator The separator symbol to use joining words used in password
13
+ # @option options [Integer] :min_length The minimum length of a word to be used in the process
14
+ # @option options [Integer] :max_length The maximum length of a word to be used in the process
2
15
  def self.generate(options = nil)
3
16
  generator = XKPassword::Generator.new
4
17
  generator.generate(options)
5
18
  end
19
+
6
20
  end
7
21
 
8
22
  require 'xkpassword/version'
@@ -1,5 +1,9 @@
1
1
  require 'xkpassword/words'
2
2
 
3
+ # The Generator class which finds words based on the requirement and using the provided options to build a
4
+ # new random passowrd.
5
+ #
6
+ # @attr_reader [XKPassword::Words] words A word database that gen provide you words for the length required
3
7
  class XKPassword::Generator
4
8
  DEFAULTS = {
5
9
  max_length: 8,
@@ -14,15 +18,26 @@ class XKPassword::Generator
14
18
  @words = XKPassword::Words.new
15
19
  end
16
20
 
17
- # options = {
18
- # separator: ' ',
19
- # words: 4,
20
- # min_length: 4,
21
- # max_length: 8
22
- # }
21
+ # Generates a password absed on the configuration provided.
23
22
  #
24
- # generator = XKPassword::Generator.new
25
- # generator.generate(options)
23
+ # @param [Hash] options The options to populate a generator
24
+ # @option options [Integer] :words The number of words to include in the generated password
25
+ # @option options [String] :separator The separator symbol to use joining words used in password
26
+ # @option options [Integer] :min_length The minimum length of a word to be used in the process
27
+ # @option options [Integer] :max_length The maximum length of a word to be used in the process
28
+ #
29
+ # @return [String] The generated password
30
+ #
31
+ # @example Populating the method with all options (current default)
32
+ # options = {
33
+ # separator: ' ',
34
+ # words: 4,
35
+ # min_length: 4,
36
+ # max_length: 8
37
+ # }
38
+ #
39
+ # generator = XKPassword::Generator.new
40
+ # generator.generate(options)
26
41
  def generate(options = nil)
27
42
  options ||= {}
28
43
  options = DEFAULTS.merge(options)
@@ -1,3 +1,3 @@
1
1
  module XKPassword
2
- VERSION = `git describe --tags`.gsub(/-.+$\n/, '')
2
+ VERSION = '0.2.3'
3
3
  end
@@ -1,5 +1,15 @@
1
1
  require 'xkpassword/store'
2
2
 
3
+ # XKPassword::Words basically is a mini database of words. Its job is to provide words
4
+ # that mach a certain criteria. At the moment this criteria is limited to the length
5
+ # of the word.
6
+ #
7
+ # This uses `XKPassword::Store` which is basically the internal store for words. It is
8
+ # expected in the future to make this store configurable and use an external source.
9
+ #
10
+ # @attr_reader [Hash] words A collection of words store in a hash with the
11
+ # corresponding key to a word be a function of the
12
+ # lenght of the word.
3
13
  class XKPassword::Words
4
14
  attr_reader :words
5
15
 
@@ -8,24 +18,44 @@ class XKPassword::Words
8
18
  setup
9
19
  end
10
20
 
21
+ # Provide an array of words having the specified number of characters in it
22
+ #
23
+ # @param length [String] The number of characters of words should contain
24
+ #
25
+ # @return [Array<String>] Words from the source that match the length requirement.
11
26
  def with_length(length)
12
27
  fail ArgumentError 'Length should be a numeric' unless length.is_a? Numeric
13
28
  words[key(length)]
14
29
  end
15
30
 
31
+
32
+ # Provides a random word with the specified length
33
+ #
34
+ # @param length [Integer] The number of characters the word should contain
35
+ #
36
+ # @return [String] A random word with length
16
37
  def random(length)
17
38
  fail ArgumentError, 'Length should be numeric' unless length.is_a? Numeric
18
39
  with_length(length).sample
19
40
  end
20
41
 
42
+ # Provide lengths available in the databse
43
+ #
44
+ # @return [Array<Integer>] A collection of lengths of words available
21
45
  def lengths
22
46
  words.keys.map{ |key| gsub(/l/, '').to_i }
23
47
  end
24
48
 
49
+ # The lenght of the shortest word
50
+ #
51
+ # @return [Integer] The length of the shortest word
25
52
  def min_length
26
53
  lengths.min
27
54
  end
28
55
 
56
+ # The length of the longest word
57
+ #
58
+ # @return [Integer] The length of the longest word
29
59
  def max_length
30
60
  lengths.max
31
61
  end
@@ -11,9 +11,15 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Hard to crack - XKPassword Generator for Ruby}
13
13
  spec.description = """
14
- Have you been interested in XKCD Password Generator as seen on http://xkpasswd.net? I was, looked
15
- arround but found no lib that did the job. So this is my take on the probelm. Hopefully useful to
16
- you guys. Comments and suggestions are appreciated.
14
+ Passwords are hard to remember, specially when they are hard to crack. I'd spend countless hours
15
+ every eyar resetting passwords and eventually running out of options that I can remember. I found
16
+ an interesting concept among a comic XKCD, it is to generate passwords using words and thus easier
17
+ to remember. Here is XKPassword, a lib which you can install to our Ruby app or run indipendant
18
+ in the command line.
19
+
20
+ Wish you a safer future.
21
+
22
+ Ziyan
17
23
  """
18
24
  spec.homepage = "https://github.com/jdeen/xkpassword"
19
25
  spec.license = "MIT"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xkpassword
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziyan Junaideen
@@ -66,13 +66,16 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.5'
69
- description: "\n Have you been interested in XKCD Password Generator as seen on
70
- http://xkpasswd.net? I was, looked\n arround but found no lib that did the job.
71
- So this is my take on the probelm. Hopefully useful to\n you guys. Comments and
72
- suggestions are appreciated.\n "
69
+ description: "\n Passwords are hard to remember, specially when they are hard to
70
+ crack. I'd spend countless hours\n every eyar resetting passwords and eventually
71
+ running out of options that I can remember. I found\n an interesting concept among
72
+ a comic XKCD, it is to generate passwords using words and thus easier\n to remember.
73
+ Here is XKPassword, a lib which you can install to our Ruby app or run indipendant\n
74
+ \ in the command line.\n\n Wish you a safer future.\n\n Ziyan\n "
73
75
  email:
74
76
  - ziyan@jdeen.com
75
- executables: []
77
+ executables:
78
+ - xkpassword
76
79
  extensions: []
77
80
  extra_rdoc_files: []
78
81
  files:
@@ -88,6 +91,7 @@ files:
88
91
  - bin/console
89
92
  - bin/setup
90
93
  - bin/xkpassword
94
+ - exe/xkpassword
91
95
  - lib/xkpassword.rb
92
96
  - lib/xkpassword/data/google-10000-english.txt
93
97
  - lib/xkpassword/generator.rb