password_strength 0.1.6 → 0.2.0

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/README.rdoc CHANGED
@@ -106,8 +106,8 @@ If you just want to overwrite the callback, you can simple do
106
106
 
107
107
  Get the files:
108
108
 
109
- * http://github.com/fnando/password_strength/raw/master/lib/password_strength.js
110
- * http://github.com/fnando/password_strength/raw/master/lib/jquery.strength.js
109
+ * http://github.com/fnando/password_strength/raw/master/javascripts/password_strength.js
110
+ * http://github.com/fnando/password_strength/raw/master/javascripts/jquery.strength.js
111
111
 
112
112
  = TO-DO
113
113
 
File without changes
File without changes
@@ -28,4 +28,13 @@ module PasswordStrength
28
28
  strength.test
29
29
  strength
30
30
  end
31
+
32
+ class << self
33
+ # You can disable PasswordStrength without having to change a single line of code. This is
34
+ # specially great on development environment.
35
+ attr_accessor :enabled
36
+ end
37
+
38
+ # Enable verification by default.
39
+ self.enabled = true
31
40
  end
@@ -1,5 +1,5 @@
1
1
  if defined?(Rails)
2
- I18n.load_path += Dir[File.dirname(__FILE__) + "/locales/**/*.yml"]
2
+ I18n.load_path += Dir[File.dirname(__FILE__) + "/../../locales/**/*.yml"]
3
3
 
4
4
  if Rails.version >= "3"
5
5
  require "active_record"
@@ -24,7 +24,7 @@ module PasswordStrength
24
24
 
25
25
  validates_each(attr_names, options) do |record, attr_name, value|
26
26
  strength = PasswordStrength.test(record.send(options[:with]), value, :exclude => options[:exclude])
27
- record.errors.add(attr_name, :too_weak, :default => options[:message]) unless strength.valid?(options[:level])
27
+ record.errors.add(attr_name, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
28
28
  end
29
29
  end
30
30
  end
@@ -7,7 +7,7 @@ module ActiveModel # :nodoc:
7
7
 
8
8
  def validate_each(record, attribute, value)
9
9
  strength = PasswordStrength.test(record.send(options[:with]), value, :exclude => options[:exclude])
10
- record.errors.add(attribute, :too_weak, :default => options[:message], :value => value) unless strength.valid?(options[:level])
10
+ record.errors.add(attribute, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
11
11
  end
12
12
 
13
13
  def check_validity!
@@ -1,8 +1,8 @@
1
1
  module PasswordStrength
2
2
  module Version # :nodoc: all
3
3
  MAJOR = 0
4
- MINOR = 1
5
- PATCH = 6
4
+ MINOR = 2
5
+ PATCH = 0
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -1,5 +1,8 @@
1
1
  en:
2
2
  activerecord:
3
- errors:
3
+ errors: &ERRORS
4
4
  messages:
5
5
  too_weak: "is not secure; use letters (uppercase and downcase), numbers and special characters"
6
+
7
+ errors:
8
+ <<: *ERRORS
@@ -1,9 +1,12 @@
1
1
  pt: &pt
2
- activerecord:
2
+ activerecord: &ERRORS
3
3
  errors:
4
4
  messages:
5
5
  too_weak: "não é segura; utilize letras (maiúsculas e mínusculas), números e caracteres especiais"
6
6
 
7
+ errors:
8
+ <<: *ERRORS
9
+
7
10
  pt-BR:
8
11
  <<: *pt
9
12
 
@@ -2,6 +2,7 @@ require "test_helper"
2
2
 
3
3
  class TestActiveRecord < Test::Unit::TestCase
4
4
  def setup
5
+ PasswordStrength.enabled = true
5
6
  Object.class_eval { remove_const("User") } if defined?(User)
6
7
  load "user.rb"
7
8
  @user = User.new
@@ -73,4 +74,10 @@ class TestActiveRecord < Test::Unit::TestCase
73
74
  @user.update_attributes :password => "^password with whitespaces 1234ASDF$"
74
75
  assert @user.errors.full_messages.any?
75
76
  end
77
+
78
+ def test_ignore_validations_when_password_strength_is_disabled
79
+ PasswordStrength.enabled = false
80
+ @user.update_attributes :password => ""
81
+ assert @user.valid?
82
+ end
76
83
  end
@@ -14,8 +14,8 @@
14
14
  }
15
15
  </style>
16
16
  <script src="jquery-1.4.2.js" type="text/javascript"></script>
17
- <script src="../lib/password_strength.js" type="text/javascript"></script>
18
- <script src="../lib/jquery.strength.js" type="text/javascript"></script>
17
+ <script src="../javascripts/password_strength.js" type="text/javascript"></script>
18
+ <script src="../javascripts/jquery.strength.js" type="text/javascript"></script>
19
19
  </head>
20
20
  <body>
21
21
 
@@ -31,10 +31,10 @@ new Test.Unit.Runner({
31
31
  testWeakStrength: function() { with(this) {
32
32
  strength.status = "weak";
33
33
  assert(strength.isWeak());
34
- assert(strength.isValid("weak"));
35
- // assertEqual(false, strength.isStrong());
36
- // assertEqual(false, strength.isGood());
37
- // assertEqual(false, strength.isInvalid());
34
+ assert(strength.isValid("weak"));
35
+ assertEqual(false, strength.isStrong());
36
+ assertEqual(false, strength.isGood());
37
+ assertEqual(false, strength.isInvalid());
38
38
  }},
39
39
 
40
40
  // Strong strength
@@ -247,12 +247,12 @@ new Test.Unit.Runner({
247
247
 
248
248
  // Exclude option as regular expression
249
249
  testExcludeOptionAsRegularExpression: function() { with(this) {
250
- strength.password = "password with whitespaces";
251
- strength.exclude = /\s/;
252
- strength.test();
250
+ strength.password = "password with whitespaces";
251
+ strength.exclude = /\s/;
252
+ strength.test();
253
253
 
254
- assertEqual("invalid", strength.status);
255
- assert(strength.isInvalid());
256
- assertEqual(false, strength.isValid());
254
+ assertEqual("invalid", strength.status);
255
+ assert(strength.isInvalid());
256
+ assertEqual(false, strength.isValid());
257
257
  }}
258
258
  });
data/test/test_helper.rb CHANGED
@@ -1,7 +1,5 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
2
1
  $KCODE = "utf8" if RUBY_VERSION < "1.9"
3
2
 
4
- require "rubygems"
5
3
  require "test/unit"
6
4
  require "ostruct"
7
5
  require "active_record"
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: password_strength
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 6
9
- version: 0.1.6
4
+ version: 0.2.0
10
5
  platform: ruby
11
6
  authors:
12
7
  - Nando Vieira
@@ -14,21 +9,19 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-03-31 00:00:00 -03:00
12
+ date: 2010-07-27 00:00:00 -03:00
18
13
  default_executable:
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: activesupport
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :runtime
31
- version_requirements: *id001
23
+ version: 2.3.5
24
+ version:
32
25
  description: |
33
26
  Validates the strength of a password according to several rules:
34
27
 
@@ -50,16 +43,16 @@ extra_rdoc_files:
50
43
  files:
51
44
  - CHANGELOG.rdoc
52
45
  - README.rdoc
53
- - lib/jquery.strength.js
54
- - lib/password_strength.js
46
+ - javascripts/jquery.strength.js
47
+ - javascripts/password_strength.js
55
48
  - lib/password_strength.rb
56
49
  - lib/password_strength/active_record.rb
57
50
  - lib/password_strength/active_record/ar2.rb
58
51
  - lib/password_strength/active_record/ar3.rb
59
52
  - lib/password_strength/base.rb
60
- - lib/password_strength/locales/en.yml
61
- - lib/password_strength/locales/pt.yml
62
53
  - lib/password_strength/version.rb
54
+ - locales/en.yml
55
+ - locales/pt.yml
63
56
  - test/active_record_test.rb
64
57
  - test/jquery-1.4.2.js
65
58
  - test/jquery_strength_test.html
@@ -85,20 +78,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
78
  requirements:
86
79
  - - ">="
87
80
  - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
81
  version: "0"
82
+ version:
91
83
  required_rubygems_version: !ruby/object:Gem::Requirement
92
84
  requirements:
93
85
  - - ">="
94
86
  - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
87
  version: "0"
88
+ version:
98
89
  requirements: []
99
90
 
100
91
  rubyforge_project:
101
- rubygems_version: 1.3.6
92
+ rubygems_version: 1.3.5
102
93
  signing_key:
103
94
  specification_version: 3
104
95
  summary: Check password strength against several rules. Includes ActiveRecord support.