zxcvbn-ruby 0.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG.md +42 -0
  4. data/CODE_OF_CONDUCT.md +130 -0
  5. data/Gemfile +8 -1
  6. data/Guardfile +26 -0
  7. data/{LICENSE → LICENSE.txt} +0 -0
  8. data/README.md +165 -9
  9. data/Rakefile +5 -1
  10. data/lib/zxcvbn.rb +10 -36
  11. data/lib/zxcvbn/crack_time.rb +44 -42
  12. data/lib/zxcvbn/data.rb +29 -0
  13. data/lib/zxcvbn/dictionary_ranker.rb +0 -2
  14. data/lib/zxcvbn/entropy.rb +3 -1
  15. data/lib/zxcvbn/feedback.rb +10 -0
  16. data/lib/zxcvbn/feedback_giver.rb +133 -0
  17. data/lib/zxcvbn/matchers/date.rb +2 -0
  18. data/lib/zxcvbn/matchers/dictionary.rb +2 -0
  19. data/lib/zxcvbn/matchers/digits.rb +2 -0
  20. data/lib/zxcvbn/matchers/l33t.rb +2 -2
  21. data/lib/zxcvbn/matchers/regex_helpers.rb +2 -0
  22. data/lib/zxcvbn/matchers/repeat.rb +2 -0
  23. data/lib/zxcvbn/matchers/sequences.rb +2 -0
  24. data/lib/zxcvbn/matchers/spatial.rb +2 -0
  25. data/lib/zxcvbn/matchers/year.rb +2 -0
  26. data/lib/zxcvbn/math.rb +2 -2
  27. data/lib/zxcvbn/omnimatch.rb +14 -3
  28. data/lib/zxcvbn/password_strength.rb +7 -3
  29. data/lib/zxcvbn/score.rb +1 -1
  30. data/lib/zxcvbn/scorer.rb +11 -0
  31. data/lib/zxcvbn/tester.rb +43 -0
  32. data/lib/zxcvbn/version.rb +1 -1
  33. data/spec/dictionary_ranker_spec.rb +2 -2
  34. data/spec/feedback_giver_spec.rb +212 -0
  35. data/spec/matchers/date_spec.rb +8 -8
  36. data/spec/matchers/dictionary_spec.rb +25 -14
  37. data/spec/matchers/digits_spec.rb +3 -3
  38. data/spec/matchers/l33t_spec.rb +15 -13
  39. data/spec/matchers/repeat_spec.rb +6 -6
  40. data/spec/matchers/sequences_spec.rb +5 -5
  41. data/spec/matchers/spatial_spec.rb +8 -8
  42. data/spec/matchers/year_spec.rb +3 -3
  43. data/spec/omnimatch_spec.rb +2 -2
  44. data/spec/scoring/crack_time_spec.rb +13 -13
  45. data/spec/scoring/entropy_spec.rb +28 -25
  46. data/spec/scoring/math_spec.rb +22 -18
  47. data/spec/support/matcher.rb +1 -1
  48. data/spec/tester_spec.rb +99 -0
  49. data/spec/zxcvbn_spec.rb +14 -39
  50. data/zxcvbn-ruby.gemspec +11 -0
  51. metadata +34 -29
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 871b2fb9d5b2db321db8625aae3ecff0f0ae13f3e9eb834ca79153c950951a89
4
+ data.tar.gz: 1eba0af7e3e6b6e982149d45a43356f91890b71328db17d03ee0bfa3cc45f37e
5
+ SHA512:
6
+ metadata.gz: 6dd4ec7906a109a2094e6f2d44606748a778c6aa35111f967cbaa143313b8b7e149b21bb926dc9d31d96c14a53489a7ec879fbc5618c6f804117a262673b5d81
7
+ data.tar.gz: d2b3b14f62904c31db52da50066fe6a4cccdb3acb058407fd1fdef5bbdac0b9e045eca99835f2875c8cb31350158f868276976a3f54d15e85d4d02ce5f3052db
@@ -0,0 +1,12 @@
1
+ before_install:
2
+ - gem install bundler
3
+ language: ruby
4
+ rvm:
5
+ - '2.5'
6
+ - '2.6'
7
+ - '2.7'
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ fast_finish: true
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ [Unreleased]: https://github.com/envato/zxcvbn-ruby/compare/v1.1.0...HEAD
10
+
11
+ ## [1.1.0] - 2020-07-16
12
+ ### Added
13
+ - Support for Ruby 2.7 ([#29])
14
+ - Gem metadata ([#29])
15
+
16
+ ### Removed
17
+ - Support for Ruby 2.3 ([#29])
18
+ - Support for Ruby 2.4 ([#29])
19
+
20
+ ### Fixed
21
+ - Invalid user dictionaries are handled more robustly ([#28])
22
+
23
+ [1.1.0]: https://github.com/envato/zxcvbn-ruby/compare/v1.0.0...v1.1.0
24
+ [28]: https://github.com/envato/zxcvbn-ruby/pull/28
25
+ [29]: https://github.com/envato/zxcvbn-ruby/pull/29
26
+
27
+ ## [1.0.0] - 2019-05-14
28
+ ### Added
29
+ - License info in the gemspec ([#21])
30
+ - More ported password checking features to bring this gem more up to date. ([#22])
31
+ - spatial - Keyboard patterns
32
+ - repeat - Repeated characters
33
+ - sequence - easily guessable sequences
34
+ - date - date associations
35
+
36
+ ### Removed
37
+ - This gem will no longer run on Ruby versions < 2.3 ([#25])
38
+
39
+ [1.0.0]: https://github.com/envato/zxcvbn-ruby/compare/v0.1.2...v1.0.0
40
+ [#21]: https://github.com/envato/zxcvbn-ruby/pull/21
41
+ [#22]: https://github.com/envato/zxcvbn-ruby/pull/22
42
+ [#25]: https://github.com/envato/zxcvbn-ruby/pull/25
@@ -0,0 +1,130 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, religion, or sexual identity
11
+ and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the
27
+ overall community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or
32
+ advances of any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email
36
+ address, without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
+ pete.johns@envato.com
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.0, available at
120
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
121
+
122
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
123
+ enforcement ladder](https://github.com/mozilla/diversity).
124
+
125
+ [homepage]: https://www.contributor-covenant.org
126
+
127
+ For answers to common questions about this code of conduct, see the FAQ at
128
+ https://www.contributor-covenant.org/faq. Translations are available at
129
+ https://www.contributor-covenant.org/translations.
130
+
data/Gemfile CHANGED
@@ -1,3 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'guard'
7
+ gem 'guard-bundler', require: false
8
+ gem 'guard-rspec', require: false
9
+ gem 'rake'
10
+ end
@@ -0,0 +1,26 @@
1
+ guard :bundler do
2
+ require 'guard/bundler'
3
+ require 'guard/bundler/verify'
4
+ helper = Guard::Bundler::Verify.new
5
+
6
+ files = ['Gemfile']
7
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
8
+
9
+ # Assume files are symlinked from somewhere
10
+ files.each { |file| watch(helper.real_path(file)) }
11
+ end
12
+
13
+ guard :rspec, cmd: "bundle exec rspec" do
14
+ require "guard/rspec/dsl"
15
+ dsl = Guard::RSpec::Dsl.new(self)
16
+
17
+ # RSpec files
18
+ rspec = dsl.rspec
19
+ watch(rspec.spec_helper) { rspec.spec_dir }
20
+ watch(rspec.spec_support) { rspec.spec_dir }
21
+ watch(rspec.spec_files)
22
+
23
+ # Ruby files
24
+ ruby = dsl.ruby
25
+ dsl.watch_spec_files_for(ruby.lib_files)
26
+ end
File without changes
data/README.md CHANGED
@@ -1,13 +1,28 @@
1
1
  # zxcvbn-ruby
2
2
 
3
- Ruby port of [zxcvbn.js](https://github.com/dropbox/zxcvbn)
3
+ This is a Ruby port of Dropbox's [zxcvbn.js][zxcvbn.js] JavaScript library.
4
4
 
5
- ## Usage
5
+ ## Development status [![Build Status](https://travis-ci.org/envato/zxcvbn-ruby.svg?branch=master)](https://travis-ci.org/envato/zxcvbn-ruby)
6
6
 
7
- Gemfile:
7
+ `zxcvbn-ruby` is considered stable and is used in projects around [Envato][envato].
8
+
9
+ After checking out the repository, run `bundle install` to install dependencies.
10
+ Then, run `rake spec` to run the tests.
11
+
12
+ To install this gem onto your local machine, run `bundle exec rake install`.
13
+
14
+ To release a new version, update the version number in `version.rb`, and then
15
+ run `bundle exec rake release`, which will create a git tag for the version,
16
+ push git commits and tags, and push the `.gem` file to
17
+ [rubygems.org](https://rubygems.org).
18
+
19
+
20
+ ## Getting started [![Gem version](https://img.shields.io/gem/v/zxcvbn-ruby.svg?style=flat-square)](https://github.com/envato/zxcvbn-ruby) [![Gem downloads](https://img.shields.io/gem/dt/zxcvbn-ruby.svg?style=flat-square)](https://rubygems.org/gems/zxcvbn-ruby)
21
+
22
+ Add the following to your project's `Gemfile`:
8
23
 
9
24
  ```ruby
10
- gem "zxcvbn-ruby", :require => 'zxcvbn'
25
+ gem 'zxcvbn-ruby', require: 'zxcvbn'
11
26
  ```
12
27
 
13
28
  Example usage:
@@ -16,8 +31,149 @@ Example usage:
16
31
  $ irb
17
32
  >> require 'zxcvbn'
18
33
  => true
19
- >> Zxcvbn.test('@lfred2004', ['alfred'])
20
- => #<Zxcvbn::Score:0x007fd467803098 @entropy=7.895, @crack_time=0.012, @crack_time_display="instant", @score=0, @match_sequence=[#<Zxcvbn::Match matched_word="alfred", token="@lfred", i=0, j=5, rank=1, pattern="dictionary", dictionary_name="user_inputs", l33t=true, sub={"@"=>"a"}, sub_display"@ -> a", base_entropy0.0, uppercase_entropy0.0, l33t_entropy1, entropy1.0, #<Zxcvbn::Match i=6, j=9, token="2004", pattern="year", entropy=6.894817763307944], @password="@lfred2004", @calc_time=0.003436>
21
- >> Zxcvbn.test('asdfghju7654rewq', ['alfred'])
22
- => #<Zxcvbn::Score:0x007fd4689c1168 @entropy=29.782, @crack_time=46159.451, @crack_time_display="14 hours", @score=2, @match_sequence=[#<Zxcvbn::Match pattern="spatial", i=0, j=15, token="asdfghju7654rewq", graph="qwerty", turns=5, shifted_count=0, entropy=29.7820508329166>], password"asdfghju7654rewq", calc_time0.00526
23
- ```
34
+ >> pp Zxcvbn.test('@lfred2004', ['alfred'])
35
+ #<Zxcvbn::Score:0x00007f7f590610c8
36
+ @calc_time=0.0055760000250302255,
37
+ @crack_time=0.012,
38
+ @crack_time_display="instant",
39
+ @entropy=7.895,
40
+ @feedback=
41
+ #<Zxcvbn::Feedback:0x00007f7f59060150
42
+ @suggestions=
43
+ ["Add another word or two. Uncommon words are better.",
44
+ "Predictable substitutions like '@' instead of 'a' don't help very much"],
45
+ @warning=nil>,
46
+ @match_sequence=
47
+ [#<Zxcvbn::Match matched_word="alfred", token="@lfred", i=0, j=5, rank=1, pattern="dictionary", dictionary_name="user_inputs", l33t=true, sub={"@"=>"a"}, sub_display="@ -> a", base_entropy=0.0, uppercase_entropy=0.0, l33t_entropy=1, entropy=1.0>,
48
+ #<Zxcvbn::Match i=6, j=9, token="2004", pattern="year", entropy=6.894817763307944>],
49
+ @password="@lfred2004",
50
+ @score=0>
51
+ => #<Zxcvbn::Score:0x00007f7f59060150>
52
+ >> pp Zxcvbn.test('asdfghju7654rewq', ['alfred'])
53
+ #<Zxcvbn::Score:0x00007f7f5a9e9248
54
+ @calc_time=0.007504999986849725,
55
+ @crack_time=46159.451,
56
+ @crack_time_display="14 hours",
57
+ @entropy=29.782,
58
+ @feedback=
59
+ #<Zxcvbn::Feedback:0x00007f7f5a9e9130
60
+ @suggestions=
61
+ ["Add another word or two. Uncommon words are better.",
62
+ "Use a longer keyboard pattern with more turns"],
63
+ @warning="Short keyboard patterns are easy to guess">,
64
+ @match_sequence=
65
+ [#<Zxcvbn::Match pattern="spatial", i=0, j=15, token="asdfghju7654rewq", graph="qwerty", turns=5, shifted_count=0, entropy=29.7820508329166>],
66
+ @password="asdfghju7654rewq",
67
+ @score=2>
68
+ => #<Zxcvbn::Score:0x00007f7f5a9e9248>
69
+ ```
70
+
71
+ ## Testing Multiple Passwords
72
+
73
+ The dictionaries used for password strength testing are loaded each request to `Zxcvbn.test`. If you you'd prefer to persist the dictionaries in memory (approx 20MB RSS) to perform lots of password tests in succession then you can use the `Zxcvbn::Tester` API:
74
+
75
+ ```ruby
76
+ $ irb
77
+ >> require 'zxcvbn'
78
+ => true
79
+ >> tester = Zxcvbn::Tester.new
80
+ => #<Zxcvbn::Tester:0x3fe99d869aa4>
81
+ >> pp tester.test('@lfred2004', ['alfred'])
82
+ #<Zxcvbn::Score:0x00007f7f586fcf50
83
+ @calc_time=0.00631899997824803,
84
+ @crack_time=0.012,
85
+ @crack_time_display="instant",
86
+ @entropy=7.895,
87
+ @feedback=
88
+ #<Zxcvbn::Feedback:0x00007f7f586fcac8
89
+ @suggestions=
90
+ ["Add another word or two. Uncommon words are better.",
91
+ "Predictable substitutions like '@' instead of 'a' don't help very much"],
92
+ @warning=nil>,
93
+ @match_sequence=
94
+ [#<Zxcvbn::Match matched_word="alfred", token="@lfred", i=0, j=5, rank=1, pattern="dictionary", dictionary_name="user_inputs", l33t=true, sub={"@"=>"a"}, sub_display="@ -> a", base_entropy=0.0, uppercase_entropy=0.0, l33t_entropy=1, entropy=1.0>,
95
+ #<Zxcvbn::Match i=6, j=9, token="2004", pattern="year", entropy=6.894817763307944>],
96
+ @password="@lfred2004",
97
+ @score=0>
98
+ => #<Zxcvbn::Score:0x00007f7f586fcf50>
99
+ >> pp tester.test('@lfred2004', ['alfred'])
100
+ #<Zxcvbn::Score:0x00007f7f56d57438
101
+ @calc_time=0.001986999996006489,
102
+ @crack_time=0.012,
103
+ @crack_time_display="instant",
104
+ @entropy=7.895,
105
+ @feedback=
106
+ #<Zxcvbn::Feedback:0x00007f7f56d56bf0
107
+ @suggestions=
108
+ ["Add another word or two. Uncommon words are better.",
109
+ "Predictable substitutions like '@' instead of 'a' don't help very much"],
110
+ @warning=nil>,
111
+ @match_sequence=
112
+ [#<Zxcvbn::Match matched_word="alfred", token="@lfred", i=0, j=5, rank=1, pattern="dictionary", dictionary_name="user_inputs", l33t=true, sub={"@"=>"a"}, sub_display="@ -> a", base_entropy=0.0, uppercase_entropy=0.0, l33t_entropy=1, entropy=1.0>,
113
+ #<Zxcvbn::Match i=6, j=9, token="2004", pattern="year", entropy=6.894817763307944>],
114
+ @password="@lfred2004",
115
+ @score=0>
116
+ => #<Zxcvbn::Score:0x00007f7f56d57438>
117
+ ```
118
+
119
+ **Note**: Storing the entropy of an encrypted or hashed value provides
120
+ information that can make cracking the value orders of magnitude easier for an
121
+ attacker. For this reason we advise you not to store the results of
122
+ `Zxcvbn::Tester#test`. Further reading: [A Tale of Security Gone Wrong](http://gavinmiller.io/2016/a-tale-of-security-gone-wrong/).
123
+
124
+ ## Contact
125
+
126
+ - [GitHub project](https://github.com/envato/zxcvbn-ruby)
127
+ - Bug reports and feature requests are welcome via [GitHub Issues](https://github.com/envato/zxcvbn-ruby/issues)
128
+
129
+ ## Maintainers
130
+
131
+ - [Pete Johns](https://github.com/johnsyweb)
132
+ - [Steve Hodgkiss](https://github.com/stevehodgkiss)
133
+
134
+ ## Authors
135
+
136
+ - [Steve Hodgkiss](https://github.com/stevehodgkiss)
137
+ - [Matthieu Aussaguel](https://github.com/matthieua)
138
+ - [_et al._](https://github.com/envato/zxcvbn-ruby/graphs/contributors)
139
+
140
+ ## License [![license](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](https://github.com/envato/zxcvbn-ruby/blob/master/LICENSE.txt)
141
+
142
+ `zxcvbn-ruby` uses MIT license, the same as [zxcvbn.js][zxcvbn.js] itself. See
143
+ [`LICENSE.txt`](https://github.com/envato/zxcvbn-ruby/blob/master/LICENSE.txt)
144
+ for details.
145
+
146
+ ## Code of Conduct
147
+
148
+ We welcome contribution from everyone. Read more about it in
149
+ [`CODE_OF_CONDUCT.md`](https://github.com/envato/zxcvbn-ruby/blob/master/CODE_OF_CONDUCT.md).
150
+
151
+ ## Contributing [![PRs welcome](https://img.shields.io/badge/PRs-welcome-orange.svg?style=flat-square)](https://github.com/envato/zxcvbn-ruby/issues)
152
+
153
+ For bug fixes, documentation changes, and features:
154
+
155
+ 1. [Fork it](./fork)
156
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
157
+ 1. Commit your changes (`git commit -am 'Add some feature'`)
158
+ 1. Push to the branch (`git push origin my-new-feature`)
159
+ 1. Create a new Pull Request
160
+
161
+ For larger new features: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction.
162
+
163
+ ## About [![code with heart by Envato](https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-Envato-ff69b4.svg?style=flat-square)](https://github.com/envato/zxcvbn-ruby)
164
+
165
+ This project is maintained by the [Envato engineering team][webuild] and funded by [Envato][envato].
166
+
167
+ [<img src="http://opensource.envato.com/images/envato-oss-readme-logo.png" alt="Envato logo">][envato]
168
+
169
+ Encouraging the use and creation of open source software is one of the ways we
170
+ serve our community. See [our other projects][oss] or [come work with us][careers]
171
+ where you'll find an incredibly diverse, intelligent and capable group of people
172
+ who help make our company succeed and make our workplace fun, friendly and
173
+ happy.
174
+
175
+ [careers]: https://envato.com/careers/?utm_source=github
176
+ [envato]: https://envato.com?utm_source=github
177
+ [oss]: https://opensource.envato.com/?utm_source=github
178
+ [webuild]: https://webuild.envato.com?utm_source=github
179
+ [zxcvbn.js]: https://github.com/dropbox/zxcvbn
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
  require "bundler/setup"
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new('spec')
7
+ task default: [:spec]
4
8
 
5
9
  task :console do
6
10
  require 'zxcvbn'
@@ -15,4 +19,4 @@ end
15
19
  task :compile_coffeescript do
16
20
  `coffee --compile --bare spec/support/js_source/{matching,scoring,init}.coffee`
17
21
  `cat spec/support/js_source/{matching,scoring,adjacency_graphs,frequency_lists,init}.js > spec/support/js_source/compiled.js`
18
- end
22
+ end
@@ -1,46 +1,20 @@
1
- require 'json'
2
1
  require 'pathname'
3
-
4
2
  require 'zxcvbn/version'
5
- require 'zxcvbn/match'
6
- require 'zxcvbn/matchers/regex_helpers'
7
- require 'zxcvbn/matchers/dictionary'
8
- require 'zxcvbn/matchers/l33t'
9
- require 'zxcvbn/matchers/spatial'
10
- require 'zxcvbn/matchers/sequences'
11
- require 'zxcvbn/matchers/repeat'
12
- require 'zxcvbn/matchers/digits'
13
- require 'zxcvbn/matchers/year'
14
- require 'zxcvbn/matchers/date'
15
- require 'zxcvbn/dictionary_ranker'
16
- require 'zxcvbn/omnimatch'
17
- require 'zxcvbn/math'
18
- require 'zxcvbn/entropy'
19
- require 'zxcvbn/crack_time'
20
- require 'zxcvbn/score'
21
- require 'zxcvbn/scorer'
22
- require 'zxcvbn/password_strength'
3
+ require 'zxcvbn/tester'
23
4
 
24
5
  module Zxcvbn
25
6
  extend self
26
7
 
27
8
  DATA_PATH = Pathname(File.expand_path('../../data', __FILE__))
28
- ADJACENCY_GRAPHS = JSON.load(DATA_PATH.join('adjacency_graphs.json').read)
29
- FREQUENCY_LISTS_PATH = DATA_PATH.join("frequency_lists")
30
- RANKED_DICTIONARIES = DictionaryRanker.rank_dictionaries(
31
- "english" => FREQUENCY_LISTS_PATH.join("english.txt").read.split,
32
- "female_names" => FREQUENCY_LISTS_PATH.join("female_names.txt").read.split,
33
- "male_names" => FREQUENCY_LISTS_PATH.join("male_names.txt").read.split,
34
- "passwords" => FREQUENCY_LISTS_PATH.join("passwords.txt").read.split,
35
- "surnames" => FREQUENCY_LISTS_PATH.join("surnames.txt").read.split
36
- )
37
-
38
- def test(password, user_inputs = [])
39
- zxcvbn = PasswordStrength.new
40
- zxcvbn.test(password, user_inputs)
41
- end
42
9
 
43
- def add_word_list(name, list)
44
- RANKED_DICTIONARIES[name] = DictionaryRanker.rank_dictionary(list)
10
+ # Returns a Zxcvbn::Score for the given password
11
+ #
12
+ # Example:
13
+ #
14
+ # Zxcvbn.test("password").score #=> 0
15
+ def test(password, user_inputs = [], word_lists = {})
16
+ tester = Tester.new
17
+ tester.add_word_lists(word_lists)
18
+ tester.test(password, user_inputs)
45
19
  end
46
20
  end