pwfoo 0.1.1 → 0.1.2

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.
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'cucumber'
7
7
  require 'cucumber/rake/task'
8
8
  require 'spec/rake/spectask'
9
9
 
10
- Echoe.new("pwfoo", "0.1.1") do |p|
10
+ Echoe.new("pwfoo", "0.1.2") do |p|
11
11
  p.author = "Perry Hertler"
12
12
  p.summary = "A gem that generates strong random passwords, scores the strength of passwords, and generates random seeds."
13
13
  p.url = "http://github.com/perry3819/pwfoo"
@@ -11,18 +11,6 @@
11
11
  # my_new_password = generate_password.generate_with_min_strength 80
12
12
  module PwFoo
13
13
  class GeneratePassword
14
- LOWER_CASE = 'lower_case'
15
- UPPER_CASE = 'upper_case'
16
- NUMBERS = 'numbers'
17
- SPECIALS = 'specials'
18
-
19
- @@character_pool = {
20
- LOWER_CASE => ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
21
- UPPER_CASE => ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
22
- NUMBERS => ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
23
- SPECIALS => ['!', '@', '#', '$', '%', '^', '*', '_', '-', '*', '(', ')']
24
- }
25
-
26
14
  def initialize(length = 10, *allowed_types)
27
15
  @length = length
28
16
  @allowed_types = allowed_types.nil? || 0 == allowed_types.length ? [LOWER_CASE, UPPER_CASE, NUMBERS] : allowed_types
@@ -46,14 +34,26 @@ module PwFoo
46
34
  gen_pw
47
35
  end
48
36
 
37
+ private
38
+ LOWER_CASE = 'lower_case'
39
+ UPPER_CASE = 'upper_case'
40
+ NUMBERS = 'numbers'
41
+ SPECIALS = 'specials'
42
+
43
+ CHARACTER_POOL = {
44
+ LOWER_CASE => ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'],
45
+ UPPER_CASE => ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
46
+ NUMBERS => ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'],
47
+ SPECIALS => ['!', '@', '#', '$', '%', '^', '*', '_', '-', '*', '(', ')']
48
+ }
49
+
49
50
  def next_char
50
51
  ta = next_type_array
51
52
  ta[rand(ta.length)]
52
53
  end
53
54
 
54
55
  def next_type_array
55
- @@character_pool[@allowed_types[rand(@allowed_types.length)]]
56
+ CHARACTER_POOL[@allowed_types[rand(@allowed_types.length)]]
56
57
  end
57
-
58
58
  end
59
59
  end
@@ -19,6 +19,27 @@ module PwFoo
19
19
  end
20
20
  end
21
21
 
22
+ def print_all
23
+ puts '=============================================================='
24
+ puts 'Score for word: ' << @word
25
+ puts 'Number of Characters: ' << number_of_characters_score.to_s
26
+ puts 'Uppercase Letters: ' << upper_case_letters_score.to_s
27
+ puts 'Lowercase Letters: ' << lower_case_letters_score.to_s
28
+ puts 'Numbers: ' << numbers_score.to_s
29
+ puts 'Symbols: ' << symbols_score.to_s
30
+ puts 'Middle Numbers or Symbols: ' << middle_numbers_or_symbols_score.to_s
31
+ puts 'Requirements: ' << requirements_score.to_s
32
+ puts 'Letters Only: ' << letters_only_deduction.to_s
33
+ puts 'Numbers Only: ' << numbers_only_deduction.to_s
34
+ puts 'Repeat Characters: ' << repeat_characters_deduction.to_s
35
+ puts 'Consecutive Uppercase Letters: ' << consecutive_upper_case_letters_deduction.to_s
36
+ puts 'Consecutive Lowercase Letters: ' << consecutive_lower_case_letters_deduction.to_s
37
+ puts 'Consecutive Numbers: ' << consecutive_numbers_deduction.to_s
38
+ puts 'Sequential Letters: ' << sequential_letters_deduction.to_s
39
+ puts 'Sequential Numbers: ' << sequential_numbers_deduction.to_s
40
+ puts '=============================================================='
41
+ end
42
+
22
43
  def number_of_characters_score
23
44
  4 * @word.length
24
45
  end
@@ -27,10 +48,22 @@ module PwFoo
27
48
  case_letters_score(UPPER_CASE_REGEX)
28
49
  end
29
50
 
51
+ def lower_case_letters_score
52
+ case_letters_score(/[a-z]/)
53
+ end
54
+
30
55
  def symbols_score
31
56
  zero_if_empty{6 * count(SYMBOLS_REGEX)}
32
57
  end
33
58
 
59
+ def letters_only_deduction
60
+ only_deduction(LETTERS_REGEX)
61
+ end
62
+
63
+ def numbers_only_deduction
64
+ only_deduction(NUMBERS_REGEX)
65
+ end
66
+
34
67
  def numbers_score
35
68
  return zero_if_empty{
36
69
  count = count(NUMBERS_REGEX)
@@ -39,34 +72,43 @@ module PwFoo
39
72
  end
40
73
 
41
74
  def repeat_characters_deduction
42
- repeats = _consecutive_count {|last, current| current == last}
75
+ repeats = consecutive_count {|last, current| current == last}
43
76
  - (repeats * (repeats - 1))
44
77
  end
45
78
 
46
79
  def consecutive_numbers_deduction
47
80
  regex = NUMBERS_REGEX
48
- repeats = _consecutive_count {|last, current| nil != current && nil != last && current.chr =~ regex && last.chr =~ regex}
81
+ repeats = consecutive_count {|last, current| nil != current && nil != last && current.chr =~ regex && last.chr =~ regex}
49
82
  return - (repeats * 2)
50
83
  end
51
84
 
85
+ def middle_numbers_or_symbols_score
86
+ middle = @word[1, @word.length-2]
87
+ @word.length < 3 ? 0 : (2 * (count(SYMBOLS_REGEX, middle) + count(NUMBERS_REGEX, middle)))
88
+ end
89
+
52
90
  def consecutive_upper_case_letters_deduction
53
- _consecutive_case_letters_deduction(UPPER_CASE_REGEX)
91
+ consecutive_case_letters_deduction(UPPER_CASE_REGEX)
54
92
  end
55
93
 
56
94
  def consecutive_lower_case_letters_deduction
57
- _consecutive_case_letters_deduction(LOWER_CASE_REGEX)
95
+ consecutive_case_letters_deduction(LOWER_CASE_REGEX)
58
96
  end
59
97
 
60
- def _consecutive_case_letters_deduction(regex)
61
- repeats = _consecutive_count {|last, current| nil != current && nil != last && current.chr =~ regex && last.chr =~ regex}
98
+ def requirements_score
99
+ 0
100
+ end
101
+
102
+ def consecutive_case_letters_deduction(regex)
103
+ repeats = consecutive_count {|last, current| nil != current && nil != last && current.chr =~ regex && last.chr =~ regex}
62
104
  - (repeats * 2)
63
105
  end
64
106
 
65
107
  def sequential_letters_deduction
66
- repeats = _three_consecutive_count(lambda {|first, second, third|
108
+ repeats = threeconsecutive_count(lambda {|first, second, third|
67
109
  consec = false
68
110
  if nil != first && first.chr =~ LETTERS_REGEX && nil != second && second.chr =~ LETTERS_REGEX && nil != third && third.chr =~ LETTERS_REGEX then
69
- consec = _are_consecutive first.chr.downcase[0], second.chr.downcase[0], third.chr.downcase[0]
111
+ consec = are_consecutive first.chr.downcase[0], second.chr.downcase[0], third.chr.downcase[0]
70
112
  end
71
113
  return consec
72
114
  })
@@ -74,21 +116,22 @@ module PwFoo
74
116
  end
75
117
 
76
118
  def sequential_numbers_deduction
77
- repeats = _three_consecutive_count(lambda {|first, second, third|
119
+ repeats = threeconsecutive_count(lambda {|first, second, third|
78
120
  consec = false
79
121
  if nil != first && first.chr =~ NUMBERS_REGEX && nil != second && second.chr =~ NUMBERS_REGEX && nil != third && first.chr =~ NUMBERS_REGEX then
80
- consec = _are_consecutive first, second, third
122
+ consec = are_consecutive first, second, third
81
123
  end
82
124
  consec
83
125
  })
84
126
  - (repeats * 3)
85
127
  end
86
128
 
87
- def _are_consecutive(first, second, third)
129
+ private
130
+ def are_consecutive(first, second, third)
88
131
  (second == (first + 1) && third == (second + 1)) || (second == (first -1) && third == (second -1))
89
132
  end
90
133
 
91
- def _three_consecutive_count(is_consecutive)
134
+ def threeconsecutive_count(is_consecutive)
92
135
  repeats = 0
93
136
  first = nil, second = nil, third = nil
94
137
 
@@ -104,7 +147,7 @@ module PwFoo
104
147
  repeats
105
148
  end
106
149
 
107
- def _consecutive_count(&is_consecutive)
150
+ def consecutive_count(&is_consecutive)
108
151
  repeats = 0
109
152
 
110
153
  cur_char = nil
@@ -118,24 +161,12 @@ module PwFoo
118
161
  repeats
119
162
  end
120
163
 
121
- def letters_only_deduction
122
- only_deduction(LETTERS_REGEX)
123
- end
124
-
125
- def numbers_only_deduction
126
- only_deduction(NUMBERS_REGEX)
127
- end
128
-
129
164
  def only_deduction(regex)
130
165
  zero_if_empty{
131
166
  @word.length == count(regex) ? (- @word.length) : 0
132
167
  }
133
168
  end
134
169
 
135
- def lower_case_letters_score
136
- case_letters_score(/[a-z]/)
137
- end
138
-
139
170
  def case_letters_score(regex)
140
171
  zero_if_empty {
141
172
  count = count(regex)
@@ -147,39 +178,8 @@ module PwFoo
147
178
  0 == number_of_characters_score ? 0 : calculator.call
148
179
  end
149
180
 
150
- def middle_numbers_or_symbols_score
151
- middle = @word[1, @word.length-2]
152
- @word.length < 3 ? 0 : (2 * (count(SYMBOLS_REGEX, middle) + count(NUMBERS_REGEX, middle)))
153
- end
154
-
155
181
  def count(regex, count_word=@word)
156
182
  count_word.scan(regex).length
157
183
  end
158
-
159
- def requirements_score
160
- 0
161
- end
162
-
163
- def print_all
164
- puts '=============================================================='
165
- puts 'Score for word: ' << @word
166
- puts 'Number of Characters: ' << number_of_characters_score.to_s
167
- puts 'Uppercase Letters: ' << upper_case_letters_score.to_s
168
- puts 'Lowercase Letters: ' << lower_case_letters_score.to_s
169
- puts 'Numbers: ' << numbers_score.to_s
170
- puts 'Symbols: ' << symbols_score.to_s
171
- puts 'Middle Numbers or Symbols: ' << middle_numbers_or_symbols_score.to_s
172
- puts 'Requirements: ' << requirements_score.to_s
173
- puts 'Letters Only: ' << letters_only_deduction.to_s
174
- puts 'Numbers Only: ' << numbers_only_deduction.to_s
175
- puts 'Repeat Characters: ' << repeat_characters_deduction.to_s
176
- puts 'Consecutive Uppercase Letters: ' << consecutive_upper_case_letters_deduction.to_s
177
- puts 'Consecutive Lowercase Letters: ' << consecutive_lower_case_letters_deduction.to_s
178
- puts 'Consecutive Numbers: ' << consecutive_numbers_deduction.to_s
179
- puts 'Sequential Letters: ' << sequential_letters_deduction.to_s
180
- puts 'Sequential Numbers: ' << sequential_numbers_deduction.to_s
181
- puts '=============================================================='
182
- end
183
-
184
184
  end
185
185
  end
@@ -14,12 +14,13 @@ module PwFoo
14
14
 
15
15
  def get_next_seed
16
16
  time_in_micro = Time.new().to_f * 100000
17
- checksum = _get_checksum
17
+ checksum = get_checksum
18
18
 
19
19
  time_in_micro * time_in_micro + checksum.to_i
20
20
  end
21
21
 
22
- def _get_checksum
22
+ private
23
+ def get_checksum
23
24
  Digest::MD5.hexdigest(`ps axww | gzip`)
24
25
  end
25
26
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pwfoo}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Perry Hertler"]
9
- s.date = %q{2009-11-17}
9
+ s.date = %q{2010-02-13}
10
10
  s.description = %q{A gem that generates strong random passwords, scores the strength of passwords, and generates random seeds.}
11
11
  s.email = %q{perry@hertler.org}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/pwfoo.rb", "lib/pwfoo/generate_password.rb", "lib/pwfoo/password_score_calculator.rb", "lib/pwfoo/password_strength.rb", "lib/pwfoo/srand_seed_generator.rb"]
@@ -11,10 +11,6 @@ module PwFoo
11
11
  end
12
12
  end
13
13
 
14
- before(:each) do
15
-
16
- end
17
-
18
14
  context "with defaults" do
19
15
  it "should have length of 7" do
20
16
  PwFoo::GeneratePassword.new(7).generate.length.should == 7
@@ -205,16 +205,16 @@ module PwFoo
205
205
  end
206
206
  context "with count" do
207
207
  it "should return 4" do
208
- @score_calculator.count(/[A-Za-z]/).should == 4
208
+ @score_calculator.send(:count, /[A-Za-z]/).should == 4
209
209
  end
210
210
  it "should return 1" do
211
- @score_calculator.count(/\d/).should == 1
211
+ @score_calculator.send(:count, /\d/).should == 1
212
212
  end
213
213
  it "should return 2" do
214
- @score_calculator.count(/\W/).should == 2
214
+ @score_calculator.send(:count, /\W/).should == 2
215
215
  end
216
216
  it "should return 2" do
217
- @score_calculator.count(/[^a-zA-Z0-9_]/).should == 2
217
+ @score_calculator.send(:count, /[^a-zA-Z0-9_]/).should == 2
218
218
  end
219
219
  end
220
220
  end
@@ -12,7 +12,7 @@ module PwFoo
12
12
  end
13
13
  context "with checksum" do
14
14
  it "should not be nil" do
15
- @seed_gen._get_checksum.should_not be_nil
15
+ @seed_gen.send(:get_checksum).should_not be_nil
16
16
  end
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwfoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perry Hertler
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 -06:00
12
+ date: 2010-02-13 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15