zxcvbn-ruby 0.0.1

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.
Files changed (57) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +22 -0
  5. data/README.md +23 -0
  6. data/Rakefile +18 -0
  7. data/data/adjacency_graphs.json +9 -0
  8. data/data/frequency_lists.yaml +85094 -0
  9. data/lib/zxcvbn.rb +37 -0
  10. data/lib/zxcvbn/crack_time.rb +51 -0
  11. data/lib/zxcvbn/dictionary_ranker.rb +23 -0
  12. data/lib/zxcvbn/entropy.rb +151 -0
  13. data/lib/zxcvbn/match.rb +13 -0
  14. data/lib/zxcvbn/matchers/date.rb +134 -0
  15. data/lib/zxcvbn/matchers/dictionary.rb +34 -0
  16. data/lib/zxcvbn/matchers/digits.rb +18 -0
  17. data/lib/zxcvbn/matchers/l33t.rb +127 -0
  18. data/lib/zxcvbn/matchers/new_l33t.rb +120 -0
  19. data/lib/zxcvbn/matchers/regex_helpers.rb +21 -0
  20. data/lib/zxcvbn/matchers/repeat.rb +32 -0
  21. data/lib/zxcvbn/matchers/sequences.rb +64 -0
  22. data/lib/zxcvbn/matchers/spatial.rb +79 -0
  23. data/lib/zxcvbn/matchers/year.rb +18 -0
  24. data/lib/zxcvbn/math.rb +63 -0
  25. data/lib/zxcvbn/omnimatch.rb +49 -0
  26. data/lib/zxcvbn/password_strength.rb +21 -0
  27. data/lib/zxcvbn/score.rb +15 -0
  28. data/lib/zxcvbn/scorer.rb +84 -0
  29. data/lib/zxcvbn/version.rb +3 -0
  30. data/spec/matchers/date_spec.rb +109 -0
  31. data/spec/matchers/dictionary_spec.rb +14 -0
  32. data/spec/matchers/digits_spec.rb +15 -0
  33. data/spec/matchers/l33t_spec.rb +85 -0
  34. data/spec/matchers/repeat_spec.rb +18 -0
  35. data/spec/matchers/sequences_spec.rb +16 -0
  36. data/spec/matchers/spatial_spec.rb +20 -0
  37. data/spec/matchers/year_spec.rb +15 -0
  38. data/spec/omnimatch_spec.rb +24 -0
  39. data/spec/scorer_spec.rb +5 -0
  40. data/spec/scoring/crack_time_spec.rb +106 -0
  41. data/spec/scoring/entropy_spec.rb +213 -0
  42. data/spec/scoring/math_spec.rb +131 -0
  43. data/spec/spec_helper.rb +54 -0
  44. data/spec/support/js_helpers.rb +35 -0
  45. data/spec/support/js_source/adjacency_graphs.js +8 -0
  46. data/spec/support/js_source/compiled.js +1188 -0
  47. data/spec/support/js_source/frequency_lists.js +10 -0
  48. data/spec/support/js_source/init.coffee +63 -0
  49. data/spec/support/js_source/init.js +95 -0
  50. data/spec/support/js_source/matching.coffee +444 -0
  51. data/spec/support/js_source/matching.js +685 -0
  52. data/spec/support/js_source/scoring.coffee +270 -0
  53. data/spec/support/js_source/scoring.js +390 -0
  54. data/spec/support/matcher.rb +35 -0
  55. data/spec/zxcvbn_spec.rb +49 -0
  56. data/zxcvbn-ruby.gemspec +20 -0
  57. metadata +167 -0
@@ -0,0 +1,35 @@
1
+ RSpec::Matchers.define :match_js_results do |expected_js_results|
2
+ match do |actual_ruby_results|
3
+ actual_ruby_results = reduce(actual_ruby_results.map(&:to_hash))
4
+ expected_js_results = reduce(expected_js_results)
5
+
6
+ @missing, @extra = [], []
7
+ expected_js_results.each do |js_result|
8
+ unless actual_ruby_results.include?(js_result)
9
+ @missing << js_result
10
+ end
11
+ end
12
+ actual_ruby_results.each do |ruby_result|
13
+ unless expected_js_results.include?(ruby_result)
14
+ @extra << ruby_result
15
+ end
16
+ end
17
+ @missing.empty? && @extra.empty?
18
+ end
19
+
20
+ failure_message_for_should do |actual|
21
+ "Matches missing from ruby results:\n#{@missing.inspect}\nMatches unique to ruby results:\n#{@extra.inspect}"
22
+ end
23
+
24
+ def reduce(results)
25
+ result = []
26
+ results.each do |hash|
27
+ new_hash = {}
28
+ (hash.keys - ['sub', 'sub_display']).sort.each do |key|
29
+ new_hash[key] = hash[key]
30
+ end
31
+ result << new_hash
32
+ end
33
+ result
34
+ end
35
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'zxcvbn over a set of example passwords' do
4
+ TEST_PASSWORDS.each do |password|
5
+ it "gives back the same score for #{password}" do
6
+ ruby_result = Zxcvbn.test(password)
7
+ js_result = js_zxcvbn(password)
8
+
9
+ ruby_result.calc_time.should_not be_nil
10
+ ruby_result.password.should eq js_result['password']
11
+ ruby_result.entropy.should eq js_result['entropy']
12
+ ruby_result.crack_time.should eq js_result['crack_time']
13
+ ruby_result.crack_time_display.should eq js_result['crack_time_display']
14
+ ruby_result.score.should eq js_result['score']
15
+ ruby_result.pattern.should eq js_result['pattern']
16
+ ruby_result.match_sequence.count.should eq js_result['match_sequence'].count
17
+ end
18
+ end
19
+
20
+ context 'with a custom user dictionary' do
21
+ it 'scores them against the user dictionary' do
22
+ result = Zxcvbn.test('themeforest', ['themeforest'])
23
+ result.entropy.should eq 0
24
+ result.score.should eq 0
25
+ end
26
+
27
+ it 'matches l33t substitutions on this dictionary' do
28
+ result = Zxcvbn.test('th3m3for3st', ['themeforest'])
29
+ result.entropy.should eq 1
30
+ result.score.should eq 0
31
+ end
32
+ end
33
+
34
+ context 'with a custom global dictionary' do
35
+ before { Zxcvbn.add_word_list('envato', ['envato']) }
36
+
37
+ it 'scores them against the dictionary' do
38
+ result = Zxcvbn.test('envato')
39
+ result.entropy.should eq 0
40
+ result.score.should eq 0
41
+ end
42
+ end
43
+
44
+ context 'nil password' do
45
+ specify do
46
+ expect { Zxcvbn.test(nil) }.to_not raise_error
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/zxcvbn/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Steve Hodgkiss", "Matthieu Aussaguel"]
6
+ gem.email = ["steve@hodgkiss.me", "matthieu.aussaguel@gmail.com"]
7
+ gem.description = %q{Ruby port of Dropboxs zxcvbn.js}
8
+ gem.summary = %q{}
9
+ gem.homepage = "http://github.com/envato/zxcvbn-ruby"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "zxcvbn-ruby"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Zxcvbn::VERSION
17
+
18
+ gem.add_development_dependency 'therubyracer'
19
+ gem.add_development_dependency 'rspec'
20
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zxcvbn-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Hodgkiss
9
+ - Matthieu Aussaguel
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-11-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: therubyracer
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rspec
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: Ruby port of Dropboxs zxcvbn.js
48
+ email:
49
+ - steve@hodgkiss.me
50
+ - matthieu.aussaguel@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rspec
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - data/adjacency_graphs.json
62
+ - data/frequency_lists.yaml
63
+ - lib/zxcvbn.rb
64
+ - lib/zxcvbn/crack_time.rb
65
+ - lib/zxcvbn/dictionary_ranker.rb
66
+ - lib/zxcvbn/entropy.rb
67
+ - lib/zxcvbn/match.rb
68
+ - lib/zxcvbn/matchers/date.rb
69
+ - lib/zxcvbn/matchers/dictionary.rb
70
+ - lib/zxcvbn/matchers/digits.rb
71
+ - lib/zxcvbn/matchers/l33t.rb
72
+ - lib/zxcvbn/matchers/new_l33t.rb
73
+ - lib/zxcvbn/matchers/regex_helpers.rb
74
+ - lib/zxcvbn/matchers/repeat.rb
75
+ - lib/zxcvbn/matchers/sequences.rb
76
+ - lib/zxcvbn/matchers/spatial.rb
77
+ - lib/zxcvbn/matchers/year.rb
78
+ - lib/zxcvbn/math.rb
79
+ - lib/zxcvbn/omnimatch.rb
80
+ - lib/zxcvbn/password_strength.rb
81
+ - lib/zxcvbn/score.rb
82
+ - lib/zxcvbn/scorer.rb
83
+ - lib/zxcvbn/version.rb
84
+ - spec/matchers/date_spec.rb
85
+ - spec/matchers/dictionary_spec.rb
86
+ - spec/matchers/digits_spec.rb
87
+ - spec/matchers/l33t_spec.rb
88
+ - spec/matchers/repeat_spec.rb
89
+ - spec/matchers/sequences_spec.rb
90
+ - spec/matchers/spatial_spec.rb
91
+ - spec/matchers/year_spec.rb
92
+ - spec/omnimatch_spec.rb
93
+ - spec/scorer_spec.rb
94
+ - spec/scoring/crack_time_spec.rb
95
+ - spec/scoring/entropy_spec.rb
96
+ - spec/scoring/math_spec.rb
97
+ - spec/spec_helper.rb
98
+ - spec/support/js_helpers.rb
99
+ - spec/support/js_source/adjacency_graphs.js
100
+ - spec/support/js_source/compiled.js
101
+ - spec/support/js_source/frequency_lists.js
102
+ - spec/support/js_source/init.coffee
103
+ - spec/support/js_source/init.js
104
+ - spec/support/js_source/matching.coffee
105
+ - spec/support/js_source/matching.js
106
+ - spec/support/js_source/scoring.coffee
107
+ - spec/support/js_source/scoring.js
108
+ - spec/support/matcher.rb
109
+ - spec/zxcvbn_spec.rb
110
+ - zxcvbn-ruby.gemspec
111
+ homepage: http://github.com/envato/zxcvbn-ruby
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 3138366731839497742
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 3138366731839497742
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.23
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: ''
141
+ test_files:
142
+ - spec/matchers/date_spec.rb
143
+ - spec/matchers/dictionary_spec.rb
144
+ - spec/matchers/digits_spec.rb
145
+ - spec/matchers/l33t_spec.rb
146
+ - spec/matchers/repeat_spec.rb
147
+ - spec/matchers/sequences_spec.rb
148
+ - spec/matchers/spatial_spec.rb
149
+ - spec/matchers/year_spec.rb
150
+ - spec/omnimatch_spec.rb
151
+ - spec/scorer_spec.rb
152
+ - spec/scoring/crack_time_spec.rb
153
+ - spec/scoring/entropy_spec.rb
154
+ - spec/scoring/math_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/js_helpers.rb
157
+ - spec/support/js_source/adjacency_graphs.js
158
+ - spec/support/js_source/compiled.js
159
+ - spec/support/js_source/frequency_lists.js
160
+ - spec/support/js_source/init.coffee
161
+ - spec/support/js_source/init.js
162
+ - spec/support/js_source/matching.coffee
163
+ - spec/support/js_source/matching.js
164
+ - spec/support/js_source/scoring.coffee
165
+ - spec/support/js_source/scoring.js
166
+ - spec/support/matcher.rb
167
+ - spec/zxcvbn_spec.rb