readable_password_generator 0.0.3 → 0.0.4
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/lib/readable_password_generator.rb +34 -55
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db4418d1296eae022c92822a1defde63cf838941a3b2c32604e0504b0aef00aa
|
4
|
+
data.tar.gz: 39aab9b7a2e3f2bfd13fe887de01386e17cc8e8e87f659de99b10222cedcd24b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec54ee71b155699db8aef82ceaaaa59cc4f576d76f1333725ad07af50bc04f3a365d74168df32226b7aece5a00721502fb4c17aabf8cb997b1292267f577b5a
|
7
|
+
data.tar.gz: a260c9167ecce3f566ca9566357d1a37941b9b88a0859d98bdbdf365d909e1b04fd3a70933e6ee8b8e93fc34f4ca29bfcafed896b1a4e47251e9032d419819f7
|
@@ -1,72 +1,51 @@
|
|
1
1
|
class Password
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def initialize(a_pw_length = DEFAULT_PW_LENGTH.sample)
|
9
|
-
@pw_length = check_length_value(a_pw_length) #checking on password length value
|
10
|
-
@vowel_pos = 0 # by default start password with a vowel
|
11
|
-
end
|
3
|
+
VOWELS = %w(a e i o u y)
|
4
|
+
CONSONANTS = %w(b c d f g h j k l m n p r s t v w x z)
|
5
|
+
DOUBLE_CONSONANTS = %w(ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
|
6
|
+
DEFAULT_LENGTH = 8
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@vowel_pos = [1, 2].sample
|
19
|
-
size, result = @pw_length, ""
|
20
|
-
count = 0
|
8
|
+
def generate(length = DEFAULT_LENGTH)
|
9
|
+
length = validate_length(length)
|
10
|
+
vowel_position = rand(0...1)
|
11
|
+
size, password = length, ""
|
12
|
+
char_set = 0
|
21
13
|
size.times do |char|
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
password << pick_letter(char_set, vowel_position)
|
15
|
+
char_set+=1
|
16
|
+
char_set = 0 if char_set==2
|
25
17
|
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def set_length(a_pw_length)
|
30
|
-
@pw_length = check_length_value(a_pw_length)
|
31
|
-
return nil
|
18
|
+
password = password[0...size]
|
32
19
|
end
|
33
20
|
|
34
21
|
private
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
else
|
47
|
-
#prioritize randomness to choosing CONSONANTS over DOUBLE_CONSONANTS (3:1)
|
48
|
-
if [1,2,3,4].sample == 4
|
49
|
-
return CONSONANTS.sample
|
50
|
-
else
|
51
|
-
return DOUBLE_CONSONANTS.sample
|
23
|
+
def validate_length(length)
|
24
|
+
if length.is_a?(NilClass)
|
25
|
+
return DEFAULT_LENGTH
|
26
|
+
elsif length.is_a?(Array)
|
27
|
+
length = length.sample
|
28
|
+
elsif length.is_a?(Range)
|
29
|
+
length = rand(length)
|
30
|
+
if length.is_a?(Integer)
|
31
|
+
if (length < 1) || (length > 100)
|
32
|
+
raise Exception.new("Length cannot be #{length}, length must be in range of 1-100!")
|
52
33
|
end
|
34
|
+
else
|
35
|
+
raise Exception.new("Length must be either an Integer or an Array or a Range value!\n#{length.class} data type is given.")
|
53
36
|
end
|
37
|
+
length
|
54
38
|
end
|
55
39
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
if a_pw_length.is_a?(NilClass)
|
60
|
-
a_pw_length = DEFAULT_PW_LENGTH.sample
|
61
|
-
elsif a_pw_length.is_a?(Array)
|
62
|
-
a_pw_length = a_pw_length.sample
|
63
|
-
elsif a_pw_length.is_a?(Integer)
|
64
|
-
if (a_pw_length < 1) || (a_pw_length > 100)
|
65
|
-
raise ArgumentError, "Length cannot be #{a_pw_length}, length must be in range of 1-100!"
|
66
|
-
end
|
40
|
+
def pick_letter(char_set, vowel_position)
|
41
|
+
if char_set == vowel_position
|
42
|
+
VOWELS.sample
|
67
43
|
else
|
68
|
-
|
44
|
+
if rand(1...4) == 4
|
45
|
+
CONSONANTS.sample
|
46
|
+
else
|
47
|
+
DOUBLE_CONSONANTS.sample
|
48
|
+
end
|
69
49
|
end
|
70
|
-
return a_pw_length
|
71
50
|
end
|
72
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readable_password_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaly Platonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: viitaly.platonov@gmail.com
|
@@ -40,5 +40,5 @@ rubyforge_project:
|
|
40
40
|
rubygems_version: 2.7.7
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary:
|
43
|
+
summary: Generates readable passwords!
|
44
44
|
test_files: []
|