password_strength 0.4.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac4e6d055b4d0ab0540abc95fc4e2ba16403b215
4
- data.tar.gz: 1e077cdf0a350ef189e28a5daa6340478c5358fd
3
+ metadata.gz: 857925632a4b2c53d8fa8f98dd2851da7e88d720
4
+ data.tar.gz: 042a655e9cfc485aa5cefd63bd1ee42c17385178
5
5
  SHA512:
6
- metadata.gz: ba9036a1ece3f16d0f81db4210bd0465a2d4f7b20a6d11a429f1dfaba86e8c65db01011ed5ae320e0a6dd411b5f588f21c620e147b4d82307e1ac25e25239b6d
7
- data.tar.gz: 61d95581e777bfb44deac202034584e0145b201fe18726bdabfd5515f6e37fe2d03ac86382286a1d70038f26079230d0bdf5e440a1613e567e08d9becc22f6a3
6
+ metadata.gz: 22a3db0a2a7ab3eb678e4a314218911dfe7815283d145fbe688429e0310b642913ef3a5042fa71e16e129ed822410914320622768b001bc1603d7eee1e83b263
7
+ data.tar.gz: ed37ba3e80c3b8b2f18e9d6c0711bf5ab091682eb26312715a3efd94b73fe3d5f93e9c0fef2369a08411cafeba47403caa3a427c27859ec599bd7127d0335310
data/Gemfile.lock CHANGED
@@ -1,74 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- password_strength (0.4.1)
4
+ password_strength (1.0.0)
5
5
  activerecord
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- activemodel (4.0.4)
11
- activesupport (= 4.0.4)
12
- builder (~> 3.1.0)
13
- activerecord (4.0.4)
14
- activemodel (= 4.0.4)
15
- activerecord-deprecated_finders (~> 1.0.2)
16
- activesupport (= 4.0.4)
17
- arel (~> 4.0.0)
18
- activerecord-deprecated_finders (1.0.3)
19
- activesupport (4.0.4)
10
+ activemodel (4.1.4)
11
+ activesupport (= 4.1.4)
12
+ builder (~> 3.1)
13
+ activerecord (4.1.4)
14
+ activemodel (= 4.1.4)
15
+ activesupport (= 4.1.4)
16
+ arel (~> 5.0.0)
17
+ activesupport (4.1.4)
20
18
  i18n (~> 0.6, >= 0.6.9)
21
- minitest (~> 4.2)
22
- multi_json (~> 1.3)
19
+ json (~> 1.7, >= 1.7.7)
20
+ minitest (~> 5.1)
23
21
  thread_safe (~> 0.1)
24
- tzinfo (~> 0.3.37)
25
- arel (4.0.2)
26
- atomic (1.1.16)
22
+ tzinfo (~> 1.1)
23
+ arel (5.0.1.20140414130214)
27
24
  awesome_print (1.2.0)
28
- builder (3.1.4)
25
+ builder (3.2.2)
29
26
  coderay (1.1.0)
30
- columnize (0.3.6)
31
- debugger (1.6.6)
32
- columnize (>= 0.3.1)
33
- debugger-linecache (~> 1.2.0)
34
- debugger-ruby_core_source (~> 1.3.2)
35
- debugger-linecache (1.2.0)
36
- debugger-ruby_core_source (1.3.2)
37
- diff-lcs (1.2.5)
38
- i18n (0.6.9)
27
+ i18n (0.6.11)
28
+ json (1.8.1)
39
29
  method_source (0.8.2)
40
- minitest (4.7.5)
41
- multi_json (1.9.2)
30
+ minitest (5.4.0)
42
31
  pry (0.9.12.6)
43
32
  coderay (~> 1.0)
44
33
  method_source (~> 0.8)
45
34
  slop (~> 3.4)
46
- pry-debugger (0.2.2)
47
- debugger (~> 1.3)
48
- pry (~> 0.9.10)
49
- pry-meta (0.0.6)
35
+ pry-meta (0.0.9)
50
36
  awesome_print
51
37
  pry
52
- pry-debugger
38
+ pry-nav
53
39
  pry-remote
40
+ pry-nav (0.2.3)
41
+ pry (~> 0.9.10)
54
42
  pry-remote (0.1.8)
55
43
  pry (~> 0.9)
56
44
  slop (~> 3.0)
57
- rake (10.2.2)
58
- rspec (2.14.1)
59
- rspec-core (~> 2.14.0)
60
- rspec-expectations (~> 2.14.0)
61
- rspec-mocks (~> 2.14.0)
62
- rspec-core (2.14.8)
63
- rspec-expectations (2.14.5)
64
- diff-lcs (>= 1.1.3, < 2.0)
65
- rspec-mocks (2.14.6)
66
- slop (3.5.0)
45
+ rake (10.3.2)
46
+ slop (3.6.0)
67
47
  sqlite3 (1.3.9)
68
48
  test-unit (2.5.5)
69
- thread_safe (0.3.1)
70
- atomic (>= 1.1.7, < 2)
71
- tzinfo (0.3.39)
49
+ thread_safe (0.3.4)
50
+ tzinfo (1.2.2)
51
+ thread_safe (~> 0.1)
72
52
 
73
53
  PLATFORMS
74
54
  ruby
@@ -77,6 +57,5 @@ DEPENDENCIES
77
57
  password_strength!
78
58
  pry-meta
79
59
  rake
80
- rspec
81
60
  sqlite3
82
61
  test-unit
data/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # Introduction
2
+
3
+ <a href="https://travis-ci.org/fnando/password_strength"><img src="https://travis-ci.org/fnando/password_strength.svg" alt="Build Status" /></a>
4
+
5
+ Validates the strength of a password according to several rules:
6
+
7
+ * size
8
+ * 3+ numbers
9
+ * 2+ special characters
10
+ * uppercased and downcased letters
11
+ * combination of numbers, letters and symbols
12
+ * password contains username
13
+ * sequences (123, abc, aaa)
14
+ * repetitions
15
+ * can't be a common password (view list at support/common.txt)
16
+
17
+ Some results:
18
+
19
+ * `123`: weak
20
+ * `123abc`: weak
21
+ * `aaaaaa`: weak
22
+ * `myPass145`: good
23
+ * `myPass145$`: strong
24
+
25
+ ## Install
26
+
27
+ ```
28
+ gem install password_strength
29
+ ```
30
+
31
+ or put this in your Gemfile:
32
+
33
+ ```ruby
34
+ gem "password_strength"
35
+ ```
36
+
37
+ If you want the source go to http://github.com/fnando/password_strength
38
+
39
+ ## Usage
40
+
41
+ ```ruby
42
+ strength = PasswordStrength.test("johndoe", "mypass")
43
+ #=> return a object
44
+
45
+ strength.good?
46
+ #=> status == :good
47
+
48
+ strength.weak?
49
+ #=> status == :weak
50
+
51
+ strength.strong?
52
+ #=> status == :strong
53
+
54
+ strength.status
55
+ #=> can be :weak, :good, :strong
56
+
57
+ strength.valid?(:strong)
58
+ #=> strength == :strong
59
+
60
+ strength.valid?(:good)
61
+ #=> strength == :good or strength == :strong
62
+ ```
63
+
64
+ ## ActiveRecord
65
+
66
+ The PasswordStrength library comes with ActiveRecord support.
67
+
68
+ ```ruby
69
+ class Person < ActiveRecord::Base
70
+ validates_strength_of :password
71
+ end
72
+ ```
73
+
74
+ The default options are `:level => :good, :with => :username`.
75
+
76
+ If you want to compare your password against other field, you have to set the `:with` option.
77
+
78
+ ```ruby
79
+ validates_strength_of :password, :with => :email
80
+ ```
81
+
82
+ The available levels are: `:weak`, `:good` and `:strong`.
83
+
84
+ ```ruby
85
+ validates_strength_of :password, :with => :email, :level => :good
86
+ ```
87
+
88
+ Also you can set level with a lambda.
89
+
90
+ ```ruby
91
+ validates_strength_of :password, :with => :email, :level => lambda {|u| :good }
92
+ ```
93
+
94
+ You can also provide a custom class/module that will test that password.
95
+
96
+ ```ruby
97
+ validates_strength_of :password, :using => CustomPasswordTester
98
+ ```
99
+
100
+ Your +CustomPasswordTester+ class should override the default implementation. In practice, you're
101
+ going to override only the +test+ method that must call one of the following methods:
102
+ `invalid!`, `weak!`, `good!` or `strong!`.
103
+
104
+ ```ruby
105
+ class CustomPasswordTester < PasswordStrength::Base
106
+ def test
107
+ if password != "mypass"
108
+ invalid!
109
+ else
110
+ strong!
111
+ end
112
+ end
113
+ end
114
+ ```
115
+
116
+ The tester above will accept only +mypass+ as password.
117
+
118
+ PasswordStrength implements two validators: `PasswordStrength::Base` and `PasswordStrength::Validators::Windows2008`.
119
+
120
+ **ATTENTION:** Custom validators are not supported by JavaScript yet!
121
+
122
+ ## JavaScript
123
+
124
+ The PasswordStrength also implements the algorithm in the JavaScript.
125
+
126
+ ```ruby
127
+ var strength = PasswordStrength.test("johndoe", "mypass");
128
+ strength.isGood();
129
+ strength.isStrong();
130
+ strength.isWeak();
131
+ strength.isValid("good");
132
+ ```
133
+
134
+ The API is basically the same!
135
+
136
+ You can use the `:exclude` option. Only regular expressions are supported for now.
137
+
138
+ ```ruby
139
+ var strength = PasswordStrength.test("johndoe", "password with whitespaces", {exclude: /\s/});
140
+ strength.isInvalid();
141
+ ```
142
+
143
+ Additionaly, a jQuery plugin is available.
144
+
145
+ ```ruby
146
+ $.strength("#username", "#password");
147
+ ```
148
+
149
+ The line above will validate the `#password` field against `#username`.
150
+ The result will be an image to the respective strength status. By default the image path will be
151
+ `/images/weak.png`, `/images/good.png` and `/images/strong.png`.
152
+
153
+ You can overwrite the image path and the default callback.
154
+
155
+ ```ruby
156
+ $.strength.weakImage = "/weak.png";
157
+ $.strength.goodImage = "/good.png";
158
+ $.strength.strongImage = "/strong.png";
159
+ $.strength.callback = function(username, password, strength) {
160
+ // do whatever you want
161
+ };
162
+ ```
163
+
164
+ If you just want to overwrite the callback, you can simple do
165
+
166
+ ```ruby
167
+ $.strength("#username", "#password", function(username, password, strength){
168
+ // do whatever you want
169
+ });
170
+ ```
171
+
172
+ Get the files:
173
+
174
+ * https://github.com/fnando/password_strength/blob/master/app/assets/javascripts/jquery_strength.js
175
+ * https://github.com/fnando/password_strength/blob/master/app/assets/javascripts/password_strength.js
176
+
177
+ If you're using asset pipeline, just add the following lines to your `application.js`.
178
+
179
+ ```javascript
180
+ //= require jquery
181
+ //= require password_strength
182
+ //= require jquery_strength
183
+ ```
184
+
185
+ ## License
186
+
187
+ (The MIT License)
188
+
189
+ Copyright © 2010-2014 Nando Vieira (http://simplesideias.com.br)
190
+
191
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
192
+
193
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
194
+
195
+ THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -2,7 +2,6 @@ require "bundler"
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require "rake/testtask"
5
- require "rdoc/task"
6
5
 
7
6
  Rake::TestTask.new do |t|
8
7
  t.libs += %w[test lib]
@@ -10,12 +9,3 @@ Rake::TestTask.new do |t|
10
9
  t.test_files = FileList["test/**/*_test.rb"]
11
10
  t.verbose = true
12
11
  end
13
-
14
- Rake::RDocTask.new do |rdoc|
15
- rdoc.main = "README.rdoc"
16
- rdoc.rdoc_dir = "doc"
17
- rdoc.title = "Password Strength"
18
- rdoc.options += %w[ --line-numbers --inline-source --charset utf-8 ]
19
- rdoc.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc")
20
- rdoc.rdoc_files.include("lib/**/*.rb")
21
- end
@@ -65,7 +65,7 @@ var PasswordStrength = (function(){
65
65
 
66
66
  switch (name) {
67
67
  case "password_size":
68
- if (this.password.length < 4) {
68
+ if (this.password.length < 6) {
69
69
  score = -100;
70
70
  } else {
71
71
  score = this.password.length * 4;
@@ -1,4 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec path: ".."
3
3
 
4
- gem "activerecord", "~> 3.2"
4
+ gem "activerecord", "~> 3.2.0"
@@ -1,4 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec path: ".."
3
3
 
4
- gem "activerecord", "~> 4.0"
4
+ gem "activerecord", "~> 4.0.0"
@@ -1,4 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec path: ".."
3
3
 
4
- gem "activerecord", "4.1.0.rc2"
4
+ gem "activerecord", "~> 4.1.0"
@@ -1,9 +1,12 @@
1
- require "active_support"
1
+ require "active_model"
2
2
  require "password_strength/base"
3
3
  require "password_strength/engine" if defined?(Rails::Engine)
4
- require "password_strength/active_record"
4
+ require "password_strength/active_model"
5
5
  require "password_strength/validators/windows2008"
6
6
 
7
+ # I18n.load_path += Dir[File.dirname(__FILE__) + "/../locales/**/*.yml"]
8
+ I18n.load_path += Dir[File.expand_path("../../locales/*.yml", __FILE__)]
9
+
7
10
  module PasswordStrength
8
11
  # Test the password strength by applying several rules.
9
12
  # The username is required to match its substring in passwords.
@@ -12,15 +12,34 @@ module ActiveModel # :nodoc:
12
12
  :record => record
13
13
  )
14
14
  strength.test
15
- record.errors.add(attribute, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
15
+ record.errors.add(attribute, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(level(record))
16
16
  end
17
17
 
18
18
  def check_validity!
19
19
  raise ArgumentError, "The :with option must be supplied" unless options.include?(:with)
20
20
  raise ArgumentError, "The :exclude options must be an array of strings or regular expression" if options[:exclude] && !options[:exclude].kind_of?(Array) && !options[:exclude].kind_of?(Regexp)
21
- raise ArgumentError, "The :level option must be one of [:weak, :good, :strong]" unless [:weak, :good, :strong].include?(options[:level])
21
+ check_level_validity!(options[:level])
22
22
  super
23
23
  end
24
+
25
+ def level(record)
26
+ if options[:level].respond_to?(:call)
27
+ level = options[:level].call(record).to_sym
28
+ check_level_validity!(level)
29
+ level
30
+ else
31
+ options[:level]
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def check_level_validity!(level)
38
+ unless [:weak, :good, :strong].include?(level) || level.respond_to?(:call)
39
+ raise ArgumentError, "The :level option must be one of [:weak, :good, :strong], a proc or a lambda"
40
+ end
41
+ end
42
+
24
43
  end
25
44
 
26
45
  module ClassMethods
@@ -1,8 +1,8 @@
1
1
  module PasswordStrength
2
2
  module Version # :nodoc: all
3
- MAJOR = 0
4
- MINOR = 4
5
- PATCH = 1
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/locales/pt.yml CHANGED
@@ -1,4 +1,4 @@
1
- pt: &pt
1
+ pt-PT: &pt
2
2
  activerecord:
3
3
  errors: &ERRORS
4
4
  messages:
@@ -9,6 +9,3 @@ pt: &pt
9
9
 
10
10
  pt-BR:
11
11
  <<: *pt
12
-
13
- pt-PT:
14
- <<: *pt
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_dependency "activerecord"
21
21
 
22
- s.add_development_dependency "rspec"
23
22
  s.add_development_dependency "rake"
24
23
  s.add_development_dependency "pry-meta"
25
24
  s.add_development_dependency "sqlite3"
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  require "test_helper"
3
3
 
4
- class TestActiveRecord < Test::Unit::TestCase
4
+ class TestActiveModel < Test::Unit::TestCase
5
5
  def setup
6
6
  PasswordStrength.enabled = true
7
7
  Object.class_eval { remove_const("User") } if defined?(User)
@@ -15,7 +15,7 @@ class TestActiveRecord < Test::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_error_messages_in_pt
18
- I18n.locale = :pt
18
+ I18n.locale = 'pt-BR'
19
19
  User.validates_strength_of :password
20
20
  @user.update_attributes :password => "123"
21
21
  assert @user.errors.full_messages.include?("Password não é segura; utilize letras (maiúsculas e mínusculas), números e caracteres especiais")
@@ -55,6 +55,35 @@ class TestActiveRecord < Test::Unit::TestCase
55
55
  assert @user.errors.full_messages.empty?
56
56
  end
57
57
 
58
+ def test_lambda_strong_level
59
+ User.validates_strength_of :password, :level => lambda {|u| :strong }
60
+
61
+ @user.update_attributes :username => "johndoe", :password => "12345asdfg"
62
+ assert @user.errors.full_messages.any?
63
+ end
64
+
65
+ def test_lambda_weak_level
66
+ User.validates_strength_of :password, :level => lambda {|u| :weak }
67
+
68
+ @user.update_attributes :username => "johndoe", :password => "johndoe"
69
+ assert @user.errors.full_messages.empty?
70
+ end
71
+
72
+ def test_lambda_with_string_return
73
+ User.validates_strength_of :password, :level => lambda {|u| 'weak' }
74
+
75
+ @user.update_attributes :username => "johndoe", :password => "johndoe"
76
+ assert @user.errors.full_messages.empty?
77
+ end
78
+
79
+ def test_lambda_incorrect_level
80
+ User.validates_strength_of :password, :level => lambda {|u| 'incorrect_level' }
81
+
82
+ assert_raise(ArgumentError, "The :level option must be one of [:weak, :good, :strong], a proc or a lambda") do
83
+ @user.update_attributes :username => "johndoe", :password => "johndoe"
84
+ end
85
+ end
86
+
58
87
  def test_custom_username
59
88
  User.validates_strength_of :password, :with => :login
60
89
 
@@ -191,7 +191,7 @@ new Test.Unit.Runner({
191
191
  // Password length
192
192
  testPasswordLength: function() { with(this) {
193
193
  strength.password = "12345";
194
- assertEqual(20, strength.scoreFor("password_size"));
194
+ assertEqual(-100, strength.scoreFor("password_size"));
195
195
  }},
196
196
 
197
197
  // Password with numbers
data/test/test_helper.rb CHANGED
@@ -1,11 +1,10 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
1
2
  require "bundler/setup"
2
3
  require "test/unit"
3
4
  require "ostruct"
4
5
  require "active_record"
5
6
 
6
7
  I18n.enforce_available_locales = false
7
-
8
- Rails = OpenStruct.new(:version => ActiveRecord::VERSION::STRING)
9
8
  require "password_strength"
10
9
 
11
10
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: password_strength
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -104,10 +90,9 @@ extra_rdoc_files: []
104
90
  files:
105
91
  - ".gitignore"
106
92
  - ".travis.yml"
107
- - CHANGELOG.rdoc
108
93
  - Gemfile
109
94
  - Gemfile.lock
110
- - README.rdoc
95
+ - README.md
111
96
  - Rakefile
112
97
  - app/assets/javascripts/jquery_strength.js
113
98
  - app/assets/javascripts/password_strength.js
@@ -115,9 +100,7 @@ files:
115
100
  - gemfiles/ar_4_0.gemfile
116
101
  - gemfiles/ar_4_1.gemfile
117
102
  - lib/password_strength.rb
118
- - lib/password_strength/active_record.rb
119
- - lib/password_strength/active_record/ar2.rb
120
- - lib/password_strength/active_record/ar3.rb
103
+ - lib/password_strength/active_model.rb
121
104
  - lib/password_strength/base.rb
122
105
  - lib/password_strength/engine.rb
123
106
  - lib/password_strength/validators/windows2008.rb
@@ -126,7 +109,7 @@ files:
126
109
  - locales/pt.yml
127
110
  - password_strength.gemspec
128
111
  - support/common.txt
129
- - test/active_record_test.rb
112
+ - test/active_model_test.rb
130
113
  - test/jquery-1.4.2.js
131
114
  - test/jquery_strength_test.html
132
115
  - test/jquery_strength_test.js
@@ -164,7 +147,7 @@ signing_key:
164
147
  specification_version: 4
165
148
  summary: Check password strength against several rules. Includes ActiveRecord support.
166
149
  test_files:
167
- - test/active_record_test.rb
150
+ - test/active_model_test.rb
168
151
  - test/jquery-1.4.2.js
169
152
  - test/jquery_strength_test.html
170
153
  - test/jquery_strength_test.js
data/CHANGELOG.rdoc DELETED
@@ -1,45 +0,0 @@
1
- = Changelog
2
-
3
- == 0.1.0 - March 5 2010
4
-
5
- * First release
6
-
7
- == 0.1.1 - March 5 2010
8
-
9
- * Added JavaScript implementation
10
-
11
- == 0.1.2 - March 5 2010
12
-
13
- * Added jQuery plugin
14
-
15
- == 0.1.3 - March 5 2010
16
-
17
- * Added localized error messages for +pt+ and +en+
18
-
19
- == 0.1.4 - March 8 2010
20
-
21
- * jQuery function can accept string instead of selectors
22
- * Added repetition penalization
23
-
24
- == 0.1.5 - March 23 2010
25
-
26
- * Added ActiveSupport as dependency
27
- * Added JavaScript implementation for JavaScript
28
-
29
- == 0.1.6 - March 31 2010
30
-
31
- * Added :exclude option
32
-
33
- == 0.2.0 - July 27 2010
34
-
35
- * PasswordStrength can be disabled; development mode says hello!
36
-
37
- == 0.3.0 - August 11 2010
38
-
39
- * Increased required password length to 6 characters
40
- * Added support for custom validators
41
- * Added Windows 2008 validator
42
-
43
- == 0.3.1 - August 12 2010
44
-
45
- * The enabled option was ignored in some cases.
data/README.rdoc DELETED
@@ -1,163 +0,0 @@
1
- = Introduction
2
-
3
- {<img src="https://travis-ci.org/fnando/password_strength.svg" alt="Build Status" />}[https://travis-ci.org/fnando/password_strength]
4
-
5
- Validates the strength of a password according to several rules:
6
-
7
- * size
8
- * 3+ numbers
9
- * 2+ special characters
10
- * uppercased and downcased letters
11
- * combination of numbers, letters and symbols
12
- * password contains username
13
- * sequences (123, abc, aaa)
14
- * repetitions
15
- * can't be a common password (view list at support/common.txt)
16
-
17
- Some results:
18
-
19
- * <tt>123</tt>: weak
20
- * <tt>123abc</tt>: weak
21
- * <tt>aaaaaa</tt>: weak
22
- * <tt>myPass145</tt>: good
23
- * <tt>myPass145$</tt>: strong
24
-
25
- = Install
26
-
27
- gem install password_strength
28
-
29
- or put this in your Gemfile:
30
-
31
- gem "password_strength"
32
-
33
- If you want the source go to http://github.com/fnando/password_strength
34
-
35
- = Usage
36
-
37
- strength = PasswordStrength.test("johndoe", "mypass")
38
- #=> return a object
39
-
40
- strength.good?
41
- #=> status == :good
42
-
43
- strength.weak?
44
- #=> status == :weak
45
-
46
- strength.strong?
47
- #=> status == :strong
48
-
49
- strength.status
50
- #=> can be :weak, :good, :strong
51
-
52
- strength.valid?(:strong)
53
- #=> strength == :strong
54
-
55
- strength.valid?(:good)
56
- #=> strength == :good or strength == :strong
57
-
58
- = ActiveRecord
59
-
60
- The PasswordStrength library comes with ActiveRecord support.
61
-
62
- class Person < ActiveRecord::Base
63
- validates_strength_of :password
64
- end
65
-
66
- The default options are <tt>:level => :good, :with => :username</tt>.
67
-
68
- If you want to compare your password against other field, you have to set the <tt>:with</tt> option.
69
-
70
- validates_strength_of :password, :with => :email
71
-
72
- The available levels are: <tt>:weak</tt>, <tt>:good</tt> and <tt>:strong</tt>
73
-
74
- You can also provide a custom class/module that will test that password.
75
-
76
- validates_strength_of :password, :using => CustomPasswordTester
77
-
78
- Your +CustomPasswordTester+ class should override the default implementation. In practice, you're
79
- going to override only the +test+ method that must call one of the following methods:
80
- <tt>invalid!</tt>, <tt>weak!</tt>, <tt>good!</tt> or <tt>strong!</tt>.
81
-
82
- class CustomPasswordTester < PasswordStrength::Base
83
- def test
84
- if password != "mypass"
85
- invalid!
86
- else
87
- strong!
88
- end
89
- end
90
- end
91
-
92
- The tester above will accept only +mypass+ as password.
93
-
94
- PasswordStrength implements two validators: <tt>PasswordStrength::Base</tt> and <tt>PasswordStrength::Validators::Windows2008</tt>.
95
-
96
- <b>ATTENTION:</b> Custom validators are not supported by JavaScript yet!
97
-
98
- = JavaScript
99
-
100
- The PasswordStrength also implements the algorithm in the JavaScript.
101
-
102
- var strength = PasswordStrength.test("johndoe", "mypass");
103
- strength.isGood();
104
- strength.isStrong();
105
- strength.isWeak();
106
- strength.isValid("good");
107
-
108
- The API is basically the same!
109
-
110
- You can use the <tt>:exclude</tt> option. Only regular expressions are supported for now.
111
-
112
- var strength = PasswordStrength.test("johndoe", "password with whitespaces", {exclude: /\s/});
113
- strength.isInvalid();
114
-
115
- Additionaly, a jQuery plugin is available.
116
-
117
- $.strength("#username", "#password");
118
-
119
- The line above will validate the <tt>#password</tt> field against <tt>#username</tt>.
120
- The result will be an image to the respective strength status. By default the image path will be
121
- <tt>/images/weak.png</tt>, <tt>/images/good.png</tt> and <tt>/images/strong.png</tt>.
122
-
123
- You can overwrite the image path and the default callback.
124
-
125
- $.strength.weakImage = "/weak.png";
126
- $.strength.goodImage = "/good.png";
127
- $.strength.strongImage = "/strong.png";
128
- $.strength.callback = function(username, password, strength) {
129
- // do whatever you want
130
- };
131
-
132
- If you just want to overwrite the callback, you can simple do
133
-
134
- $.strength("#username", "#password", function(username, password, strength){
135
- // do whatever you want
136
- });
137
-
138
- Get the files:
139
-
140
- * http://github.com/fnando/password_strength/raw/master/app/assets/javascripts/password_strength.js
141
- * http://github.com/fnando/password_strength/raw/master/app/assets/javascripts/jquery.strength.js
142
-
143
- If you're using asset pipeline, just add the following lines to your `application.js`.
144
-
145
- ```javascript
146
- //= require jquery
147
- //= require password_strength
148
- //= require jquery_strength
149
- ```
150
-
151
- = License
152
-
153
- (The MIT License)
154
-
155
- Copyright © 2010-2014:
156
-
157
- * Nando Vieira (http://simplesideias.com.br)
158
-
159
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
160
-
161
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
162
-
163
- THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,10 +0,0 @@
1
- if defined?(Rails)
2
- I18n.load_path += Dir[File.dirname(__FILE__) + "/../../locales/**/*.yml"]
3
-
4
- if Rails.version >= "3"
5
- require "active_record"
6
- require "password_strength/active_record/ar3"
7
- else
8
- require "password_strength/active_record/ar2"
9
- end
10
- end
@@ -1,64 +0,0 @@
1
- module PasswordStrength
2
- module ActiveRecord
3
- # Validates that the specified attributes are not weak (according to several rules).
4
- #
5
- # class Person < ActiveRecord::Base
6
- # validates_strength_of :password
7
- # end
8
- #
9
- # The default options are <tt>:level => :good, :with => :username</tt>.
10
- #
11
- # If you want to compare your password against other field, you have to set the <tt>:with</tt> option.
12
- #
13
- # validates_strength_of :password, :with => :email
14
- #
15
- # The available levels are: <tt>:weak</tt>, <tt>:good</tt> and <tt>:strong</tt>
16
- #
17
- # You can also provide a custom class/module that will test that password.
18
- #
19
- # validates_strength_of :password, :using => CustomPasswordTester
20
- #
21
- # Your +CustomPasswordTester+ class should override the default implementation. In practice, you're
22
- # going to override only the +test+ method that must call one of the following methods:
23
- # <tt>invalid!</tt>, <tt>weak!</tt>, <tt>good!</tt> or <tt>strong!</tt>.
24
- #
25
- # class CustomPasswordTester < PasswordStrength::Base
26
- # def test
27
- # if password != "mypass"
28
- # invalid!
29
- # else
30
- # strong!
31
- # end
32
- # end
33
- # end
34
- #
35
- # The tester above will accept only +mypass+ as password.
36
- #
37
- # PasswordStrength implements two validators: <tt>PasswordStrength::Base</tt> and <tt>PasswordStrength::Validators::Windows2008</tt>.
38
- #
39
- def validates_strength_of(*attr_names)
40
- options = attr_names.extract_options!
41
- options.reverse_merge!(:level => :good, :with => :username, :using => PasswordStrength::Base)
42
-
43
- raise ArgumentError, "The :with option must be supplied" unless options.include?(:with)
44
- raise ArgumentError, "The :exclude options must be an array of string or regular expression" if options[:exclude] && !options[:exclude].kind_of?(Array) && !options[:exclude].kind_of?(Regexp)
45
- raise ArgumentError, "The :level option must be one of [:weak, :good, :strong]" unless [:weak, :good, :strong].include?(options[:level])
46
-
47
- validates_each(attr_names, options) do |record, attr_name, value|
48
- next unless PasswordStrength.enabled
49
-
50
- strength = options[:using].new(record.send(options[:with]), value,
51
- :exclude => options[:exclude],
52
- :record => record
53
- )
54
-
55
- strength.test
56
- record.errors.add(attr_name, :too_weak, options) unless strength.valid?(options[:level])
57
- end
58
- end
59
- end
60
- end
61
-
62
- class ActiveRecord::Base # :nodoc:
63
- extend PasswordStrength::ActiveRecord
64
- end