xkpassword 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ require 'xkpassword/words'
2
+
3
+ class XKPassword::Generator
4
+ DEFAULTS = {
5
+ max_length: 8,
6
+ min_length: 4,
7
+ separator: '-',
8
+ words: 4,
9
+ }
10
+
11
+ attr_reader :words
12
+
13
+ def initialize
14
+ @words = XKPassword::Words.new
15
+ end
16
+
17
+ # options = {
18
+ # separator: ' ',
19
+ # words: 4,
20
+ # min_length: 4,
21
+ # max_length: 8
22
+ # }
23
+ #
24
+ # generator = XKPassword::Generator.new
25
+ # generator.generate(options)
26
+ def generate(options = nil)
27
+ options ||= {}
28
+ options = DEFAULTS.merge(options)
29
+ length_vals = (options[:min_length]..options[:max_length]).to_a
30
+
31
+ data = options[:words].times.map do
32
+ word = words.random(length_vals.sample)
33
+ upcase = [true, false].sample
34
+ word = word.upcase if upcase
35
+ word
36
+ end
37
+
38
+ data.join(options[:separator])
39
+ end
40
+
41
+ end
@@ -0,0 +1,16 @@
1
+ class XKPassword::Store
2
+ SOURCE = 'google-10000-english.txt'
3
+
4
+ attr_reader :data
5
+
6
+ def initialize
7
+ load_data
8
+ end
9
+
10
+ private
11
+
12
+ def load_data
13
+ path = "#{ File.dirname(__FILE__) }/data/#{ SOURCE }"
14
+ @data = IO.readlines(path).map{ |item| item.gsub(/\n/, '') }
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module XKPassword
2
+ VERSION = `git describe --tags`.gsub(/-.+$\n/, '')
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'xkpassword/store'
2
+
3
+ class XKPassword::Words
4
+ attr_reader :words
5
+
6
+ def initialize
7
+ @words = {}
8
+ setup
9
+ end
10
+
11
+ def with_length(length)
12
+ fail ArgumentError 'Length should be a numeric' unless length.is_a? Numeric
13
+ words[key(length)]
14
+ end
15
+
16
+ def random(length)
17
+ fail ArgumentError, 'Length should be numeric' unless length.is_a? Numeric
18
+ with_length(length).sample
19
+ end
20
+
21
+ def lengths
22
+ words.keys.map{ |key| gsub(/l/, '').to_i }
23
+ end
24
+
25
+ def min_length
26
+ lengths.min
27
+ end
28
+
29
+ def max_length
30
+ lengths.max
31
+ end
32
+
33
+ private
34
+
35
+ def setup
36
+ store = XKPassword::Store.new
37
+ data = store.data
38
+
39
+ data.each do |datum|
40
+ k = key(datum.length)
41
+ words[k] = [] unless words[k]
42
+ words[k] << datum
43
+ end
44
+ end
45
+
46
+ def key(length)
47
+ "l#{ length }"
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xkpassword/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xkpassword"
8
+ spec.version = XKPassword::VERSION
9
+ spec.authors = ["Ziyan Junaideen"]
10
+ spec.email = ["ziyan@jdeen.com"]
11
+
12
+ spec.summary = %q{Hard to crack - XKPassword Generator for Ruby}
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.
17
+ """
18
+ spec.homepage = "https://github.com/jdeen/xkpassword"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "artii", "~> 2.1"
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.5"
30
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xkpassword
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Ziyan Junaideen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: artii
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
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 "
73
+ email:
74
+ - ziyan@jdeen.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".ruby-gemset"
82
+ - ".ruby-version"
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - bin/xkpassword
91
+ - lib/xkpassword.rb
92
+ - lib/xkpassword/data/google-10000-english.txt
93
+ - lib/xkpassword/generator.rb
94
+ - lib/xkpassword/store.rb
95
+ - lib/xkpassword/version.rb
96
+ - lib/xkpassword/words.rb
97
+ - xkpassword.gemspec
98
+ homepage: https://github.com/jdeen/xkpassword
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Hard to crack - XKPassword Generator for Ruby
122
+ test_files: []