xkpassword 0.3.3 → 0.4.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/Gemfile +1 -0
- data/README.md +5 -1
- data/exe/xkpassword +1 -1
- data/lib/xkpassword/generator.rb +32 -5
- data/lib/xkpassword/version.rb +1 -1
- data/lib/xkpassword.rb +1 -1
- data/mise.toml +14 -0
- metadata +4 -5
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a85ce5f07e033d7e20eb30071b644c118ac1e67426c321df01ec2574590eb06f
|
|
4
|
+
data.tar.gz: f5505a6dddc828b5cb673d32c90b29dd073a0b7143017b2766e54274eba61315
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37b272ecbb57d3e652fa01e6ddd1c047241640e957dd733d9323e57c9daa0e92e5fbb8dbbcf3c82eb5eb5f1c72ca51bac2188f60464d6e4c57dfb6453b07ec4a
|
|
7
|
+
data.tar.gz: 47778296384d3398000a0b4cf3f890d847e11461da40f0f8a269ebe4bc6a718a8194b4ea3e3369f8a81c5fb056bcc85e3ee5c89b8568819b72286ce423ce88c2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -73,6 +73,7 @@ require 'xkpassword'
|
|
|
73
73
|
options = {
|
|
74
74
|
max_length: 8,
|
|
75
75
|
min_length: 4,
|
|
76
|
+
case_transform: :capitalize,
|
|
76
77
|
separator: '-',
|
|
77
78
|
words: 4,
|
|
78
79
|
}
|
|
@@ -89,6 +90,7 @@ require 'xkpassword/generator'
|
|
|
89
90
|
options = {
|
|
90
91
|
max_length: 8,
|
|
91
92
|
min_length: 4,
|
|
93
|
+
case_transform: :capitalize,
|
|
92
94
|
separator: '-',
|
|
93
95
|
words: 4,
|
|
94
96
|
}
|
|
@@ -99,6 +101,9 @@ generator.generate(options)
|
|
|
99
101
|
# 10.times { generator.generate(options) }
|
|
100
102
|
```
|
|
101
103
|
|
|
104
|
+
`case_transform` supports `:upcase`, `:downcase`, and `:capitalize`, and applies the
|
|
105
|
+
selected transform to every generated word in the password.
|
|
106
|
+
|
|
102
107
|
## The GEM
|
|
103
108
|
|
|
104
109
|
I run a policy of tagging any improvement done for the code base. For example, I just
|
|
@@ -140,4 +145,3 @@ conduct.
|
|
|
140
145
|
## License
|
|
141
146
|
|
|
142
147
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
143
|
-
|
data/exe/xkpassword
CHANGED
|
@@ -39,10 +39,10 @@ OptionParser.new do |opts|
|
|
|
39
39
|
opts.on('--min-length [INTEGER]', 'Minimum length of a word') { |min| options[:min_length] = min.to_i }
|
|
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
|
+
opts.on('--case-transform [STRING]', 'Transform each word using upcase, downcase, or capitalize') { |case_transform| options[:case_transform] = case_transform }
|
|
42
43
|
end.parse!
|
|
43
44
|
|
|
44
45
|
puts message if options[:info]
|
|
45
46
|
puts XKPassword::VERSION if options[:version]
|
|
46
47
|
puts XKPassword.generate(options) if !options[:info] && !options[:version]
|
|
47
48
|
|
|
48
|
-
|
data/lib/xkpassword/generator.rb
CHANGED
|
@@ -6,6 +6,7 @@ require 'xkpassword/words'
|
|
|
6
6
|
# @attr_reader [XKPassword::Words] words A word database that gen provide you words for the length required
|
|
7
7
|
class XKPassword::Generator
|
|
8
8
|
DEFAULTS = {
|
|
9
|
+
case_transform: nil,
|
|
9
10
|
max_length: 8,
|
|
10
11
|
min_length: 4,
|
|
11
12
|
separator: '-',
|
|
@@ -25,6 +26,7 @@ class XKPassword::Generator
|
|
|
25
26
|
# @option options [String] :separator The separator symbol to use joining words used in password
|
|
26
27
|
# @option options [Integer] :min_length The minimum length of a word to be used in the process
|
|
27
28
|
# @option options [Integer] :max_length The maximum length of a word to be used in the process
|
|
29
|
+
# @option options [String, Symbol] :case_transform The transform to apply to every generated word
|
|
28
30
|
#
|
|
29
31
|
# @return [String] The generated password
|
|
30
32
|
#
|
|
@@ -33,7 +35,8 @@ class XKPassword::Generator
|
|
|
33
35
|
# separator: ' ',
|
|
34
36
|
# words: 4,
|
|
35
37
|
# min_length: 4,
|
|
36
|
-
# max_length: 8
|
|
38
|
+
# max_length: 8,
|
|
39
|
+
# case_transform: :capitalize
|
|
37
40
|
# }
|
|
38
41
|
#
|
|
39
42
|
# generator = XKPassword::Generator.new
|
|
@@ -41,16 +44,40 @@ class XKPassword::Generator
|
|
|
41
44
|
def generate(options = nil)
|
|
42
45
|
options ||= {}
|
|
43
46
|
options = DEFAULTS.merge(options)
|
|
47
|
+
case_transform = normalize_case_transform(options[:case_transform])
|
|
44
48
|
length_vals = (options[:min_length]..options[:max_length]).to_a
|
|
45
49
|
|
|
46
50
|
data = options[:words].times.map do
|
|
47
51
|
word = words.random(length_vals.sample)
|
|
48
|
-
|
|
49
|
-
word = word.upcase if upcase
|
|
50
|
-
word
|
|
52
|
+
transform_word(word, case_transform)
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
data.join(options[:separator])
|
|
54
56
|
end
|
|
55
|
-
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def transform_word(word, case_transform)
|
|
61
|
+
return randomly_upcase(word) unless case_transform
|
|
62
|
+
|
|
63
|
+
word.public_send(case_transform)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def randomly_upcase(word)
|
|
67
|
+
upcase = [true, false].sample
|
|
68
|
+
word = word.upcase if upcase
|
|
69
|
+
word
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def normalize_case_transform(case_transform)
|
|
73
|
+
return nil if case_transform.nil?
|
|
74
|
+
|
|
75
|
+
case_transform = case_transform.to_sym if case_transform.is_a?(String)
|
|
76
|
+
valid_case_transforms = [:upcase, :downcase, :capitalize]
|
|
77
|
+
|
|
78
|
+
return case_transform if valid_case_transforms.include?(case_transform)
|
|
79
|
+
|
|
80
|
+
fail ArgumentError, "case_transform should be one of: #{ valid_case_transforms.join(', ') }"
|
|
81
|
+
end
|
|
82
|
+
|
|
56
83
|
end
|
data/lib/xkpassword/version.rb
CHANGED
data/lib/xkpassword.rb
CHANGED
|
@@ -12,6 +12,7 @@ module XKPassword
|
|
|
12
12
|
# @option options [String] :separator The separator symbol to use joining words used in password
|
|
13
13
|
# @option options [Integer] :min_length The minimum length of a word to be used in the process
|
|
14
14
|
# @option options [Integer] :max_length The maximum length of a word to be used in the process
|
|
15
|
+
# @option options [String, Symbol] :case_transform The transform to apply to every generated word
|
|
15
16
|
def self.generate(options = nil)
|
|
16
17
|
generator = XKPassword::Generator.new
|
|
17
18
|
generator.generate(options)
|
|
@@ -22,4 +23,3 @@ end
|
|
|
22
23
|
require 'xkpassword/version'
|
|
23
24
|
require 'xkpassword/generator'
|
|
24
25
|
|
|
25
|
-
|
data/mise.toml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[tools]
|
|
2
|
+
ruby = "3.3"
|
|
3
|
+
|
|
4
|
+
[tasks.test]
|
|
5
|
+
description = "Run the test suite"
|
|
6
|
+
run = "bundle exec rspec"
|
|
7
|
+
|
|
8
|
+
[tasks.format]
|
|
9
|
+
description = "Format and lint the code with RuboCop"
|
|
10
|
+
run = "bundle exec rubocop -a"
|
|
11
|
+
|
|
12
|
+
[tasks.publish]
|
|
13
|
+
description = "Build and publish the gem to RubyGems"
|
|
14
|
+
run = "bundle exec rake release"
|
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.4.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:
|
|
11
|
+
date: 2026-04-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: artii
|
|
@@ -81,8 +81,6 @@ extra_rdoc_files: []
|
|
|
81
81
|
files:
|
|
82
82
|
- ".gitignore"
|
|
83
83
|
- ".rspec"
|
|
84
|
-
- ".ruby-gemset"
|
|
85
|
-
- ".ruby-version"
|
|
86
84
|
- ".travis.yml"
|
|
87
85
|
- CODE_OF_CONDUCT.md
|
|
88
86
|
- Gemfile
|
|
@@ -99,6 +97,7 @@ files:
|
|
|
99
97
|
- lib/xkpassword/store.rb
|
|
100
98
|
- lib/xkpassword/version.rb
|
|
101
99
|
- lib/xkpassword/words.rb
|
|
100
|
+
- mise.toml
|
|
102
101
|
- xkpassword.gemspec
|
|
103
102
|
homepage: https://github.com/jdeen/xkpassword
|
|
104
103
|
licenses:
|
|
@@ -119,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
119
118
|
- !ruby/object:Gem::Version
|
|
120
119
|
version: '0'
|
|
121
120
|
requirements: []
|
|
122
|
-
rubygems_version: 3.
|
|
121
|
+
rubygems_version: 3.5.22
|
|
123
122
|
signing_key:
|
|
124
123
|
specification_version: 4
|
|
125
124
|
summary: Hard to crack - XKPassword Generator for Ruby
|
data/.ruby-gemset
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
xkpassword_gem
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.3.0
|