xkpassword 0.4.0 → 0.5.0
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 +4 -4
- data/README.md +10 -18
- data/exe/xkpassword +1 -1
- data/lib/xkpassword/generator.rb +90 -14
- data/lib/xkpassword/version.rb +1 -1
- data/lib/xkpassword.rb +17 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9feced30408ade895b492ff621703dd5d6a1cb6f6d4aaa6fe195534a249cb519
|
|
4
|
+
data.tar.gz: 8f7bde17464c36aba01028a650daaa3e37d357018e5892bd9331384f25068a6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 158d3daab0101987cb7062a907125d80858aa7dbfdea51c6448ade83d4e155e5af31a87e37715ebde7a1965572008d2f56e64d747e53eb21a9a51e66c948d95b
|
|
7
|
+
data.tar.gz: cfa02254cb10af01efe5387605d9036750c419031e40bb47cb8a2b23f97c4364ba534f66e3629b3b335dc450fb99d965f5827b654e0e5556d81a2f202eae7664
|
data/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Or install it yourself as:
|
|
|
53
53
|
## Usage
|
|
54
54
|
|
|
55
55
|
You can use this app stand-alone in the command line or include it in any of your Ruby
|
|
56
|
-
applications.
|
|
56
|
+
applications. For a fuller guide to presets and examples, see [doc/README.md](doc/README.md).
|
|
57
57
|
|
|
58
58
|
### Comamnd Line
|
|
59
59
|
The commandline application accepts the same collection of configuration options as would
|
|
@@ -71,11 +71,7 @@ full list of options.
|
|
|
71
71
|
require 'xkpassword'
|
|
72
72
|
|
|
73
73
|
options = {
|
|
74
|
-
|
|
75
|
-
min_length: 4,
|
|
76
|
-
case_transform: :capitalize,
|
|
77
|
-
separator: '-',
|
|
78
|
-
words: 4,
|
|
74
|
+
preset: :security,
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
XKPassword.generate(options)
|
|
@@ -88,11 +84,7 @@ the following as then it will only load and parse the databse once.
|
|
|
88
84
|
require 'xkpassword/generator'
|
|
89
85
|
|
|
90
86
|
options = {
|
|
91
|
-
|
|
92
|
-
min_length: 4,
|
|
93
|
-
case_transform: :capitalize,
|
|
94
|
-
separator: '-',
|
|
95
|
-
words: 4,
|
|
87
|
+
preset: :wifi,
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
generator = XKPassword::Generator.new
|
|
@@ -101,18 +93,18 @@ generator.generate(options)
|
|
|
101
93
|
# 10.times { generator.generate(options) }
|
|
102
94
|
```
|
|
103
95
|
|
|
96
|
+
`preset` supports `:xkcd` (default), `:web32`, `:wifi`, `:security`, and `:apple_id`.
|
|
97
|
+
You can still override any individual option in the selected preset.
|
|
98
|
+
|
|
99
|
+
The default `:xkcd` preset keeps the gem's original behavior of generating 4 words.
|
|
100
|
+
|
|
104
101
|
`case_transform` supports `:upcase`, `:downcase`, and `:capitalize`, and applies the
|
|
105
102
|
selected transform to every generated word in the password.
|
|
106
103
|
|
|
107
104
|
## The GEM
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
functional aspect of the app.
|
|
112
|
-
|
|
113
|
-
I am thinking of releasing gems only on functional updates (real code changes) that
|
|
114
|
-
happen with new features and bug fixes. So for now, there will be no 0.3.0v available
|
|
115
|
-
in Ruby GEMs and the latest would be 0.2.3.
|
|
106
|
+
Releases are intended for functional updates such as new features and bug fixes.
|
|
107
|
+
Check the Git tags or RubyGems release history for the latest published version.
|
|
116
108
|
|
|
117
109
|
## Development
|
|
118
110
|
|
data/exe/xkpassword
CHANGED
|
@@ -40,9 +40,9 @@ OptionParser.new do |opts|
|
|
|
40
40
|
opts.on('--max-length [INTEGER]', 'Maximum length of a word') { |max| options[:max_length] = max.to_i }
|
|
41
41
|
opts.on('--separator [STRING]', 'The separator to separate password') { |separator| options[:separator] = separator }
|
|
42
42
|
opts.on('--case-transform [STRING]', 'Transform each word using upcase, downcase, or capitalize') { |case_transform| options[:case_transform] = case_transform }
|
|
43
|
+
opts.on('--preset [STRING]', 'Preset to use: xkcd, web32, wifi, security, or apple_id') { |preset| options[:preset] = preset }
|
|
43
44
|
end.parse!
|
|
44
45
|
|
|
45
46
|
puts message if options[:info]
|
|
46
47
|
puts XKPassword::VERSION if options[:version]
|
|
47
48
|
puts XKPassword.generate(options) if !options[:info] && !options[:version]
|
|
48
|
-
|
data/lib/xkpassword/generator.rb
CHANGED
|
@@ -2,16 +2,60 @@ require 'xkpassword/words'
|
|
|
2
2
|
|
|
3
3
|
# The Generator class which finds words based on the requirement and using the provided options to build a
|
|
4
4
|
# new random passowrd.
|
|
5
|
+
# Presets provide convenient defaults for common password styles, and callers can override any
|
|
6
|
+
# preset-derived value by passing explicit generation options.
|
|
5
7
|
#
|
|
6
8
|
# @attr_reader [XKPassword::Words] words A word database that gen provide you words for the length required
|
|
7
9
|
class XKPassword::Generator
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
# The preset used when `:preset` is omitted.
|
|
11
|
+
DEFAULT_PRESET = :xkcd
|
|
12
|
+
|
|
13
|
+
# Built-in password presets.
|
|
14
|
+
#
|
|
15
|
+
# - `:xkcd` generates 4 words between 4 and 8 letters separated by `-`, preserving the gem's
|
|
16
|
+
# original default behavior.
|
|
17
|
+
# - `:web32` generates 4 shorter words between 4 and 5 letters separated by `-`.
|
|
18
|
+
# - `:wifi` generates 6 words between 4 and 8 letters separated by `-`.
|
|
19
|
+
# - `:security` generates 6 lowercase words between 4 and 8 letters separated by spaces.
|
|
20
|
+
# - `:apple_id` generates 3 words between 4 and 7 letters separated by `-`.
|
|
21
|
+
PRESETS = {
|
|
22
|
+
xkcd: {
|
|
23
|
+
case_transform: nil,
|
|
24
|
+
max_length: 8,
|
|
25
|
+
min_length: 4,
|
|
26
|
+
separator: '-',
|
|
27
|
+
words: 4,
|
|
28
|
+
},
|
|
29
|
+
web32: {
|
|
30
|
+
case_transform: nil,
|
|
31
|
+
max_length: 5,
|
|
32
|
+
min_length: 4,
|
|
33
|
+
separator: '-',
|
|
34
|
+
words: 4,
|
|
35
|
+
},
|
|
36
|
+
wifi: {
|
|
37
|
+
case_transform: nil,
|
|
38
|
+
max_length: 8,
|
|
39
|
+
min_length: 4,
|
|
40
|
+
separator: '-',
|
|
41
|
+
words: 6,
|
|
42
|
+
},
|
|
43
|
+
security: {
|
|
44
|
+
case_transform: :downcase,
|
|
45
|
+
max_length: 8,
|
|
46
|
+
min_length: 4,
|
|
47
|
+
separator: ' ',
|
|
48
|
+
words: 6,
|
|
49
|
+
},
|
|
50
|
+
apple_id: {
|
|
51
|
+
case_transform: nil,
|
|
52
|
+
max_length: 7,
|
|
53
|
+
min_length: 4,
|
|
54
|
+
separator: '-',
|
|
55
|
+
words: 3,
|
|
56
|
+
},
|
|
14
57
|
}
|
|
58
|
+
VALID_CASE_TRANSFORMS = [:upcase, :downcase, :capitalize]
|
|
15
59
|
|
|
16
60
|
attr_reader :words
|
|
17
61
|
|
|
@@ -20,8 +64,14 @@ class XKPassword::Generator
|
|
|
20
64
|
end
|
|
21
65
|
|
|
22
66
|
# Generates a password absed on the configuration provided.
|
|
67
|
+
# A preset supplies a base configuration and any explicit options passed in `options` override
|
|
68
|
+
# those preset defaults.
|
|
23
69
|
#
|
|
24
70
|
# @param [Hash] options The options to populate a generator
|
|
71
|
+
# @option options [String, Symbol] :preset The preset to use. Supports `:xkcd`, `:web32`,
|
|
72
|
+
# `:wifi`, `:security`, and `:apple_id`.
|
|
73
|
+
# String values like `"apple_id"` and `"apple-id"`
|
|
74
|
+
# are normalized to `:apple_id`. Defaults to `:xkcd`.
|
|
25
75
|
# @option options [Integer] :words The number of words to include in the generated password
|
|
26
76
|
# @option options [String] :separator The separator symbol to use joining words used in password
|
|
27
77
|
# @option options [Integer] :min_length The minimum length of a word to be used in the process
|
|
@@ -30,20 +80,37 @@ class XKPassword::Generator
|
|
|
30
80
|
#
|
|
31
81
|
# @return [String] The generated password
|
|
32
82
|
#
|
|
33
|
-
# @example
|
|
83
|
+
# @example Using the default xkcd preset
|
|
84
|
+
# generator = XKPassword::Generator.new
|
|
85
|
+
# generator.generate
|
|
86
|
+
#
|
|
87
|
+
# @example Using the security preset
|
|
88
|
+
# generator = XKPassword::Generator.new
|
|
89
|
+
# generator.generate(preset: :security)
|
|
90
|
+
#
|
|
91
|
+
# @example Populating the method with a preset and explicit overrides
|
|
34
92
|
# options = {
|
|
93
|
+
# preset: :security,
|
|
35
94
|
# separator: ' ',
|
|
36
|
-
# words:
|
|
95
|
+
# words: 6,
|
|
37
96
|
# min_length: 4,
|
|
38
97
|
# max_length: 8,
|
|
39
|
-
# case_transform: :
|
|
98
|
+
# case_transform: :downcase
|
|
40
99
|
# }
|
|
41
100
|
#
|
|
42
101
|
# generator = XKPassword::Generator.new
|
|
43
102
|
# generator.generate(options)
|
|
103
|
+
#
|
|
104
|
+
# @example Built-in preset defaults
|
|
105
|
+
# :xkcd # 4 words, 4..8 letters, "-" separator, random per-word uppercasing
|
|
106
|
+
# :web32 # 4 words, 4..5 letters, "-" separator, random per-word uppercasing
|
|
107
|
+
# :wifi # 6 words, 4..8 letters, "-" separator, random per-word uppercasing
|
|
108
|
+
# :security # 6 words, 4..8 letters, " " separator, lowercase
|
|
109
|
+
# :apple_id # 3 words, 4..7 letters, "-" separator, random per-word uppercasing
|
|
44
110
|
def generate(options = nil)
|
|
45
|
-
options
|
|
46
|
-
|
|
111
|
+
options = (options || {}).dup
|
|
112
|
+
preset = normalize_preset(options.delete(:preset))
|
|
113
|
+
options = PRESETS.fetch(preset).merge(options)
|
|
47
114
|
case_transform = normalize_case_transform(options[:case_transform])
|
|
48
115
|
length_vals = (options[:min_length]..options[:max_length]).to_a
|
|
49
116
|
|
|
@@ -73,11 +140,20 @@ class XKPassword::Generator
|
|
|
73
140
|
return nil if case_transform.nil?
|
|
74
141
|
|
|
75
142
|
case_transform = case_transform.to_sym if case_transform.is_a?(String)
|
|
76
|
-
valid_case_transforms = [:upcase, :downcase, :capitalize]
|
|
77
143
|
|
|
78
|
-
return case_transform if
|
|
144
|
+
return case_transform if VALID_CASE_TRANSFORMS.include?(case_transform)
|
|
145
|
+
|
|
146
|
+
fail ArgumentError, "case_transform should be one of: #{ VALID_CASE_TRANSFORMS.join(', ') }"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def normalize_preset(preset)
|
|
150
|
+
return DEFAULT_PRESET if preset.nil?
|
|
151
|
+
|
|
152
|
+
preset = preset.strip.downcase.tr(' -', '_').to_sym if preset.is_a?(String)
|
|
153
|
+
|
|
154
|
+
return preset if PRESETS.key?(preset)
|
|
79
155
|
|
|
80
|
-
fail ArgumentError, "
|
|
156
|
+
fail ArgumentError, "preset should be one of: #{ PRESETS.keys.join(', ') }"
|
|
81
157
|
end
|
|
82
158
|
|
|
83
159
|
end
|
data/lib/xkpassword/version.rb
CHANGED
data/lib/xkpassword.rb
CHANGED
|
@@ -7,12 +7,29 @@ module XKPassword
|
|
|
7
7
|
# use the `XKPassword::Generator` class as it will be faster since it will only need to load
|
|
8
8
|
# the dictionary once.
|
|
9
9
|
#
|
|
10
|
+
# Presets provide named defaults for common password styles, and any explicit options passed to
|
|
11
|
+
# this method override the selected preset.
|
|
12
|
+
#
|
|
10
13
|
# @param [Hash] options The options to populate a generator
|
|
14
|
+
# @option options [String, Symbol] :preset The preset to use. Supports `:xkcd`, `:web32`,
|
|
15
|
+
# `:wifi`, `:security`, and `:apple_id`.
|
|
16
|
+
# Defaults to `:xkcd`.
|
|
17
|
+
# - `:xkcd` uses 4 words of 4..8 letters joined by `-`
|
|
18
|
+
# - `:web32` uses 4 words of 4..5 letters joined by `-`
|
|
19
|
+
# - `:wifi` uses 6 words of 4..8 letters joined by `-`
|
|
20
|
+
# - `:security` uses 6 lowercase words of 4..8 letters joined by spaces
|
|
21
|
+
# - `:apple_id` uses 3 words of 4..7 letters joined by `-`
|
|
11
22
|
# @option options [Integer] :words The number of words to include in the generated password
|
|
12
23
|
# @option options [String] :separator The separator symbol to use joining words used in password
|
|
13
24
|
# @option options [Integer] :min_length The minimum length of a word to be used in the process
|
|
14
25
|
# @option options [Integer] :max_length The maximum length of a word to be used in the process
|
|
15
26
|
# @option options [String, Symbol] :case_transform The transform to apply to every generated word
|
|
27
|
+
#
|
|
28
|
+
# @example Generate with the default preset
|
|
29
|
+
# XKPassword.generate
|
|
30
|
+
#
|
|
31
|
+
# @example Generate with a preset and override one of its defaults
|
|
32
|
+
# XKPassword.generate(preset: :apple_id, separator: '.')
|
|
16
33
|
def self.generate(options = nil)
|
|
17
34
|
generator = XKPassword::Generator.new
|
|
18
35
|
generator.generate(options)
|
|
@@ -22,4 +39,3 @@ end
|
|
|
22
39
|
|
|
23
40
|
require 'xkpassword/version'
|
|
24
41
|
require 'xkpassword/generator'
|
|
25
|
-
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: xkpassword
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ziyan Junaideen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: artii
|