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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a2e7085db65b76b910ff634abf7f2b6b8f2fb970a32f5f1f38584eac46e63bb
4
- data.tar.gz: d7113c876ca76e3813f960f30e7ceee306b3e8e2f6d418c57612e76f16a9f904
3
+ metadata.gz: db4418d1296eae022c92822a1defde63cf838941a3b2c32604e0504b0aef00aa
4
+ data.tar.gz: 39aab9b7a2e3f2bfd13fe887de01386e17cc8e8e87f659de99b10222cedcd24b
5
5
  SHA512:
6
- metadata.gz: 50e5d39e65d6372cde0daf4e34d1a2dc1cf893ad4ba883c5343e96c1d95a0f25390afbecfac5e7a5d07074ad1b327666afe34855833f2ca462f659a193d6f0e9
7
- data.tar.gz: 428a23df865243504e135a02d33544905a7b08452e8c522aadf3c449e7f0e1fde990d2d32db9749c7ae827c5f7cd68e4437ccd2bb48830cd6cf119e930d60db7
6
+ metadata.gz: 3ec54ee71b155699db8aef82ceaaaa59cc4f576d76f1333725ad07af50bc04f3a365d74168df32226b7aece5a00721502fb4c17aabf8cb997b1292267f577b5a
7
+ data.tar.gz: a260c9167ecce3f566ca9566357d1a37941b9b88a0859d98bdbdf365d909e1b04fd3a70933e6ee8b8e93fc34f4ca29bfcafed896b1a4e47251e9032d419819f7
@@ -1,72 +1,51 @@
1
1
  class Password
2
2
 
3
- #minimum default length is set to 10 by security concerns of a readable password
4
- DEFAULT_PW_LENGTH = [10,11,12,13,14,15,16,17,18]
5
-
6
- attr_reader :pw_length
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
- #generate password of a required length
14
- def gener_passw
15
- #set position for a vowel: either to start a password with it first or not:
16
- # 0 - start password with a vowel
17
- # 1 - start password with a consonat(s)
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
- count = 0 if count==2
23
- count+=1
24
- result << take_char(count)
14
+ password << pick_letter(char_set, vowel_position)
15
+ char_set+=1
16
+ char_set = 0 if char_set==2
25
17
  end
26
- return result = result[0...size]
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
- #sets of character used in generating
37
- VOWELS = %w(a e i o u y)
38
- CONSONANTS = %w(b c d f g h j k l m n p r s t v w x z)
39
- #to diversify the end result
40
- DOUBLE_CONSONANTS = %w(ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
41
-
42
- #take a sample char from a set of letters
43
- def take_char(set_type)
44
- if set_type == @vowel_pos
45
- return VOWELS.sample
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
- #checking length value - does it meet specified criteria:
57
- # - must consist of numeric value or numeric range
58
- def check_length_value(a_pw_length)
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
- raise ArgumentError, "Length must be either an Integer or a Range value!\n#{a_pw_length.class} data type is given. "
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.3
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-04 00:00:00.000000000 Z
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: Home for the project is
43
+ summary: Generates readable passwords!
44
44
  test_files: []