toolrack 0.8.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toolrack/condition_utils.rb +4 -4
- data/lib/toolrack/data_conversion_utils.rb +1 -1
- data/lib/toolrack/password_utils.rb +301 -0
- data/lib/toolrack/version.rb +1 -1
- data/lib/toolrack.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2252d8ade57bb6f6bb8792c05eafdd148e6949f0ba161232f28cad4deba98d0
|
4
|
+
data.tar.gz: 10f5349171d87a626c13e6a84c990eadf64f03c772f68ef439194a3f7fbc6aa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e80e95f7326b95365df855b9b56ceb71663d31794e257b304fc1baf24df9144cad100a52bd3fc695347806dcc2173da0d80f9a6b5004c27cd480dfbb264367
|
7
|
+
data.tar.gz: 1b535e82f1c75c4bee974ed41f3c1d6f0705c352572a332cb2f4f4a670d4be77fb63fd2d68a15b8591ae626b6721f8473f4049d4a276aa21131da7eb15640ff3
|
@@ -15,10 +15,10 @@ module Antrapol
|
|
15
15
|
else
|
16
16
|
obj.empty?
|
17
17
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
elsif obj.respond_to?(:length)
|
19
|
+
obj.length == 0
|
20
|
+
elsif obj.respond_to?(:size)
|
21
|
+
obj.size == 0
|
22
22
|
else
|
23
23
|
false
|
24
24
|
end
|
@@ -0,0 +1,301 @@
|
|
1
|
+
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
module Antrapol
|
5
|
+
module ToolRack
|
6
|
+
module PasswordUtils
|
7
|
+
include Antrapol::ToolRack::ConditionUtils
|
8
|
+
|
9
|
+
class PasswordUtilsError < StandardError; end
|
10
|
+
|
11
|
+
# complexity
|
12
|
+
# 1 : lowercase alphabet
|
13
|
+
# 2 : lower + upper alphabet
|
14
|
+
# 3 : lower + upper + number
|
15
|
+
# 4 : lower + upper + number + symbol
|
16
|
+
def generate_random_password(length = 12, opts = { complexity: 4, enforce_quality: true })
|
17
|
+
|
18
|
+
|
19
|
+
length = 12 if is_empty?(length)
|
20
|
+
length = length.to_i
|
21
|
+
length = 12 if length <= 0
|
22
|
+
|
23
|
+
logger.debug "Length : #{length}"
|
24
|
+
|
25
|
+
if not_empty?(opts)
|
26
|
+
complexity = opts[:complexity] || 4
|
27
|
+
|
28
|
+
raise PasswordUtilsError, "Password length too short but complexity too high. Not able generate the password with required complexity." if length <= complexity
|
29
|
+
|
30
|
+
enforce_quality = opts[:enforce_quality] || true
|
31
|
+
end
|
32
|
+
|
33
|
+
complexity = 4 if is_empty?(complexity)
|
34
|
+
complexity = 4 if complexity > 4
|
35
|
+
complexity = 1 if complexity < 1
|
36
|
+
|
37
|
+
logger.debug "Complexity : #{complexity}"
|
38
|
+
|
39
|
+
enforce_quality = true if is_empty?(enforce_quality) or not is_bool?(enforce_quality)
|
40
|
+
|
41
|
+
res = []
|
42
|
+
antropy = [("a".."z"),("A".."Z"),(0..9),("!".."?")]
|
43
|
+
selection = antropy[0..complexity-1].map { |s| s.to_a }.flatten
|
44
|
+
|
45
|
+
fres = nil
|
46
|
+
loop do
|
47
|
+
|
48
|
+
len = length
|
49
|
+
processed = 0
|
50
|
+
loop do
|
51
|
+
#res += selection.sample(length)
|
52
|
+
res += selection.sort_by { SecureRandom.random_number }
|
53
|
+
break if res.length >= length
|
54
|
+
end
|
55
|
+
|
56
|
+
fres = res[0...length].join
|
57
|
+
|
58
|
+
if enforce_quality
|
59
|
+
case complexity
|
60
|
+
when 1
|
61
|
+
if all_lowercase_alpha?(fres)
|
62
|
+
break
|
63
|
+
else
|
64
|
+
logger.debug "Failed lowercase alpha quality check. #{fres} - Regenerating..."
|
65
|
+
res.clear
|
66
|
+
end
|
67
|
+
when 2
|
68
|
+
st, dst = all_alpha?(fres)
|
69
|
+
if st
|
70
|
+
break
|
71
|
+
else
|
72
|
+
logger.debug "Failed all alpha quality check. #{dst} - Regenerating..."
|
73
|
+
res.clear
|
74
|
+
end
|
75
|
+
when 3
|
76
|
+
st, dst = all_alpha_numeric?(fres)
|
77
|
+
if st
|
78
|
+
break
|
79
|
+
else
|
80
|
+
logger.debug "Failed alpha numeric quality check. #{dst} - Regenerating"
|
81
|
+
res.clear
|
82
|
+
end
|
83
|
+
when 4
|
84
|
+
st, dst = all_alpha_numeric_and_symbol?(fres)
|
85
|
+
if st
|
86
|
+
break
|
87
|
+
else
|
88
|
+
logger.debug "Failed alpha numeric + symbol quality check. #{fres} / #{dst} - Regenerating"
|
89
|
+
res.clear
|
90
|
+
end
|
91
|
+
else
|
92
|
+
logger.debug "Unknown complexity?? #{complexity}"
|
93
|
+
break
|
94
|
+
end
|
95
|
+
else
|
96
|
+
break
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
fres
|
102
|
+
|
103
|
+
#length = 12 if is_empty?(length)
|
104
|
+
#length = length.to_i
|
105
|
+
#length = 12 if length <= 0
|
106
|
+
|
107
|
+
#antropy = ('!'..'~').to_a
|
108
|
+
#antropy.sort_by { SecureRandom.random_number }.join[0...length]
|
109
|
+
end
|
110
|
+
alias_method :gen_rand_pass, :generate_random_password
|
111
|
+
alias_method :gen_pass, :generate_random_password
|
112
|
+
|
113
|
+
def all_lowercase_alpha?(str)
|
114
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
115
|
+
|
116
|
+
s = str.split("")
|
117
|
+
lalpha = ('a'..'z').to_a
|
118
|
+
|
119
|
+
(s.difference(lalpha).length == 0)
|
120
|
+
end
|
121
|
+
|
122
|
+
def has_lowercase_alpha?(str)
|
123
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
124
|
+
|
125
|
+
s = str.split("")
|
126
|
+
lalpha = ('a'..'z').to_a
|
127
|
+
|
128
|
+
(s & lalpha).length > 0
|
129
|
+
end
|
130
|
+
|
131
|
+
def all_uppercase_alpha?(str)
|
132
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
133
|
+
|
134
|
+
s = str.split("")
|
135
|
+
ualpha = ('A'..'Z').to_a
|
136
|
+
|
137
|
+
s.difference(ualpha).length == 0
|
138
|
+
end
|
139
|
+
|
140
|
+
def has_uppercase_alpha?(str)
|
141
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
142
|
+
|
143
|
+
s = str.split("")
|
144
|
+
ualpha = ('A'..'Z').to_a
|
145
|
+
|
146
|
+
(s & ualpha).length > 0
|
147
|
+
end
|
148
|
+
|
149
|
+
def all_alpha?(str)
|
150
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
151
|
+
|
152
|
+
s = str.split("")
|
153
|
+
lalpha = ('a'..'z').to_a
|
154
|
+
ualpha = ('A'..'Z').to_a
|
155
|
+
num = ('0'..'9').to_a
|
156
|
+
sym = ('!'..'?').to_a
|
157
|
+
|
158
|
+
alpha = [lalpha, ualpha].flatten
|
159
|
+
|
160
|
+
t1 = (alpha.difference(s).length == 0)
|
161
|
+
t2 = (alpha.difference(s).length == 0)
|
162
|
+
|
163
|
+
t3 = (s & num).length > 0
|
164
|
+
t4 = (s & sym).length > 0
|
165
|
+
|
166
|
+
[!(t1 or t2 or t3 or t4), res = { has_lower_alpha: t1, has_upper_alpha: t2, has_num: t3, has_symbol: t4 }]
|
167
|
+
end
|
168
|
+
|
169
|
+
def has_alpha?(str)
|
170
|
+
return false if is_empty?(str) or not str.is_a?(String)
|
171
|
+
|
172
|
+
s = str.split("")
|
173
|
+
lalpha = ('a'..'z').to_a
|
174
|
+
ualpha = ('A'..'Z').to_a
|
175
|
+
alpha = [lalpha, ualpha].flatten
|
176
|
+
|
177
|
+
(alpha & s).length > 0
|
178
|
+
end
|
179
|
+
|
180
|
+
def has_number?(str)
|
181
|
+
return false if is_empty?(str)
|
182
|
+
|
183
|
+
str = str.to_s if not str.is_a?(String)
|
184
|
+
|
185
|
+
s = str.split("")
|
186
|
+
num = ('0'..'9').to_a
|
187
|
+
|
188
|
+
(s & num).length > 0
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
def all_number?(str)
|
193
|
+
return false if is_empty?(str)
|
194
|
+
|
195
|
+
str = str.to_s if not str.is_a?(String)
|
196
|
+
|
197
|
+
s = str.split("")
|
198
|
+
num = ('0'..'9').to_a
|
199
|
+
|
200
|
+
!(s.difference(num).length > 0)
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
def all_symbol?(str)
|
205
|
+
return false if is_empty?(str)
|
206
|
+
|
207
|
+
s = str.split("")
|
208
|
+
sym = ('!'..'?').to_a
|
209
|
+
!(s.difference(sym).length > 0)
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
def has_symbol?(str)
|
214
|
+
return false if is_empty?(str)
|
215
|
+
|
216
|
+
s = str.split("")
|
217
|
+
sym = ('!'..'?').to_a
|
218
|
+
|
219
|
+
p (s & sym)
|
220
|
+
(s & sym).length > 0
|
221
|
+
end
|
222
|
+
|
223
|
+
|
224
|
+
def all_alpha_numeric?(str)
|
225
|
+
return false if is_empty?(str)
|
226
|
+
|
227
|
+
s = str.split("")
|
228
|
+
lalpha = ('a'..'z').to_a
|
229
|
+
ualpha = ('A'..'Z').to_a
|
230
|
+
num = ('0'..'9').to_a
|
231
|
+
sym = ('!'..'?').to_a
|
232
|
+
sym = sym.difference(num)
|
233
|
+
|
234
|
+
t1 = ((s & lalpha).length > 0)
|
235
|
+
t2 = ((s & ualpha).length > 0)
|
236
|
+
t3 = ((s & num).length > 0)
|
237
|
+
|
238
|
+
t4 = ((s & sym).length > 0)
|
239
|
+
|
240
|
+
[(t1 and t2 and t3 and !t4), res = { has_lower_alpha: t1, has_upper_alpha: t2, has_num: t3, has_symbol: t4 }]
|
241
|
+
end
|
242
|
+
|
243
|
+
def has_alpha_numeric?(str)
|
244
|
+
return false if is_empty?(str)
|
245
|
+
|
246
|
+
s = str.split("")
|
247
|
+
lalpha = ('a'..'z').to_a
|
248
|
+
ualpha = ('A'..'Z').to_a
|
249
|
+
num = ('0'..'9').to_a
|
250
|
+
alphanum = [lalpha, ualpha, num].flatten
|
251
|
+
|
252
|
+
(s & alphanum).length > 0
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
def all_alpha_numeric_and_symbol?(str)
|
257
|
+
return false if is_empty?(str)
|
258
|
+
|
259
|
+
s = str.split("")
|
260
|
+
lalpha = ('a'..'z').to_a
|
261
|
+
ualpha = ('A'..'Z').to_a
|
262
|
+
num = ('0'..'9').to_a
|
263
|
+
sym = ('!'..'?').to_a
|
264
|
+
sym = sym.difference(num)
|
265
|
+
|
266
|
+
t1 = ((s & lalpha).length > 0)
|
267
|
+
t2 = ((s & ualpha).length > 0)
|
268
|
+
t3 = ((s & num).length > 0)
|
269
|
+
t4 = ((s & sym).length > 0)
|
270
|
+
|
271
|
+
[(t1 and t2 and t3 and t4), res = { has_lower_alpha: t1, has_upper_alpha: t2, has_num: t3, has_symbol: t4 }]
|
272
|
+
end
|
273
|
+
|
274
|
+
def has_alpha_numeric_or_symbol?(str)
|
275
|
+
return false if is_empty?(str)
|
276
|
+
|
277
|
+
s = str.split("")
|
278
|
+
lalpha = ('a'..'z').to_a
|
279
|
+
ualpha = ('A'..'Z').to_a
|
280
|
+
num = ('0'..'9').to_a
|
281
|
+
sym = ('!'..'?').to_a
|
282
|
+
sym = sym.difference(num)
|
283
|
+
|
284
|
+
t1 = ((s & lalpha).length > 0)
|
285
|
+
t2 = ((s & ualpha).length > 0)
|
286
|
+
t3 = ((s & num).length > 0)
|
287
|
+
t4 = ((s & sym).length > 0)
|
288
|
+
|
289
|
+
[(t1 or t2 or t3 or t4), res = { has_lower_alpha: t1, has_upper_alpha: t2, has_num: t3, has_symbol: t4 }]
|
290
|
+
end
|
291
|
+
|
292
|
+
private
|
293
|
+
def logger
|
294
|
+
logger = Antrapol::ToolRack::Logger.instance.glogger
|
295
|
+
logger.tag = :pass_utils
|
296
|
+
logger
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
data/lib/toolrack/version.rb
CHANGED
data/lib/toolrack.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative 'toolrack/condition_utils'
|
|
11
11
|
require_relative 'toolrack/process_utils'
|
12
12
|
require_relative 'toolrack/runtime_utils'
|
13
13
|
require_relative 'toolrack/data_conversion_utils'
|
14
|
+
require_relative 'toolrack/password_utils'
|
14
15
|
|
15
16
|
module Antrapol
|
16
17
|
module ToolRack
|
@@ -22,5 +23,7 @@ end
|
|
22
23
|
|
23
24
|
ToolRack = Antrapol::ToolRack
|
24
25
|
ToolRack::DataConv = Antrapol::ToolRack::DataConversionUtils
|
26
|
+
ToolRack::CondUtils = ToolRack::ConditionUtils
|
27
|
+
ToolRack::PassUtils = ToolRack::PasswordUtils
|
25
28
|
|
26
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toolrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tlogger
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/toolrack/data_conversion_utils.rb
|
74
74
|
- lib/toolrack/exception_utils.rb
|
75
75
|
- lib/toolrack/global.rb
|
76
|
+
- lib/toolrack/password_utils.rb
|
76
77
|
- lib/toolrack/process_utils.rb
|
77
78
|
- lib/toolrack/runtime_utils.rb
|
78
79
|
- lib/toolrack/utils.rb
|