simple_form_password_with_hints 0.0.10 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d83415f47aa069c001ae4ef753a4f5c8adf2d51ecef3810f0b73c09d9d4cccd9
4
- data.tar.gz: a617f17aa73ce03dfa9a014d0beb09403d802a608d375d566dd6ed7e112feac0
3
+ metadata.gz: a6066f856ad9bd7cb20038699df175148218fdbd44715a34faca291b6a8559c2
4
+ data.tar.gz: 5480b2dfa95a9c4b82cc4428689c479d40364035b5af4f7ca0b17e10778dc807
5
5
  SHA512:
6
- metadata.gz: eca8cf2fc11d72662bb5c273716a9cda54fe71889e183971a4fd6516729f099a092c131cd645ab0ee1217acdf226aa82ffeed576e22a0d95ad30467777942382
7
- data.tar.gz: 6d7e1328160d9f33a9a3f583ce466a6c2a7788d47e3ea6974d96e63eca717de3d8467d4f03b05b6f6c932a846bf3426b9bd4c0336a614e8d16a90bbafc6cc0cd
6
+ metadata.gz: de49dc0af3fbbda27f1b66585ecf4553b6169ea1752af49bd586d2aa3ec0103bd5118aaf4e71f21197d4495aecd009b6573306c4eb5a074a504c78c9bc0c3e54
7
+ data.tar.gz: 7cf4d043bc797cce6a2c072f9e1b46bb37d4f60d09ddb0d438e9be9a6bf3af20fa3c9b835837e8576aa453814d914399a254a64bf0b5bf617459152d1dfa31a3
data/.gitignore CHANGED
@@ -6,4 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- /test/dummy/tmp/
9
+
10
+ .DS_Store
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ gem 'pg', '~> 1.1'
11
11
  gem 'bootsnap', '>= 1.4.4', require: false
12
12
  gem 'devise'
13
13
  gem 'bootstrap'
14
+ gem 'sassc-rails'
14
15
  gem 'jquery-rails'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_form_password_with_hints (0.0.10)
4
+ simple_form_password_with_hints (0.0.12)
5
5
  rails
6
6
  simple_form
7
7
 
@@ -199,14 +199,31 @@ GEM
199
199
  responders (3.1.1)
200
200
  actionpack (>= 5.2)
201
201
  railties (>= 5.2)
202
+ sassc (2.4.0)
203
+ ffi (~> 1.9)
204
+ sassc-rails (2.1.2)
205
+ railties (>= 4.0.0)
206
+ sassc (>= 2.0)
207
+ sprockets (> 3.0)
208
+ sprockets-rails
209
+ tilt
202
210
  securerandom (0.3.1)
203
211
  simple_form (5.3.1)
204
212
  actionpack (>= 5.2)
205
213
  activemodel (>= 5.2)
214
+ sprockets (4.2.2)
215
+ concurrent-ruby (~> 1.0)
216
+ logger
217
+ rack (>= 2.2.4, < 4)
218
+ sprockets-rails (3.5.2)
219
+ actionpack (>= 6.1)
220
+ activesupport (>= 6.1)
221
+ sprockets (>= 3.0.0)
206
222
  sqlite3 (2.1.1)
207
223
  mini_portile2 (~> 2.8.0)
208
224
  stringio (3.1.1)
209
225
  thor (1.3.2)
226
+ tilt (2.7.0)
210
227
  timeout (0.4.1)
211
228
  tzinfo (2.0.6)
212
229
  concurrent-ruby (~> 1.0)
@@ -229,6 +246,7 @@ DEPENDENCIES
229
246
  jquery-rails
230
247
  listen
231
248
  pg (~> 1.1)
249
+ sassc-rails
232
250
  simple_form
233
251
  simple_form_password_with_hints!
234
252
  sqlite3
data/README.md CHANGED
@@ -58,11 +58,12 @@ becomes
58
58
  <%= f.input :password,
59
59
  as: :password_with_hints,
60
60
  validators: {
61
- length: 6,
61
+ minlength: 8,
62
+ maxlength: 128,
62
63
  uppercase_char: true,
63
64
  lowercase_char: true,
64
65
  numeric_char: true,
65
- special_char: '#&@?!'
66
+ special_char: true
66
67
  } %>
67
68
  ```
68
69
 
@@ -92,8 +93,20 @@ Basically in your `User` model you will have to add a test like this:
92
93
  validate :password_complexity
93
94
 
94
95
  def password_complexity
95
- # Regexp extracted from https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
96
- return if password.blank? || password =~ /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!,@$%^&*+£µ-]).{8,70}$/
96
+ return if password.blank?
97
+
98
+ has_uppercase = password =~ /[A-Z]/
99
+ has_lowercase = password =~ /[a-z]/
100
+ has_number = password =~ /[0-9]/
101
+ has_special_char = password =~ /[^A-z0-9]/
102
+ is_right_length = (8..128).include?(password.length)
103
+
104
+ return if has_uppercase &&
105
+ has_lowercase &&
106
+ has_number &&
107
+ has_special_char &&
108
+ is_right_length
109
+
97
110
  errors.add :password, 'Your password is not strong enough'
98
111
  end
99
112
  ```
@@ -101,28 +114,28 @@ end
101
114
  This regex matches the validators:
102
115
  ```erb
103
116
  validators: {
104
- length: 8,
117
+ minlength: 8,
118
+ maxlength: 128,
105
119
  uppercase_char: true,
106
120
  lowercase_char: true,
107
121
  numeric_char: true,
108
- special_char: '#?!,@$%^&*+£µ-'
122
+ special_char: true,
109
123
  }
110
124
  ```
111
125
 
112
- If you use `Devise` you might want to use the gem setup directly. And maybe add the special chars list in the configuration.
113
- So in you `config/application.rb` you might add `config.allowed_special_chars = '#?!,@$%^&*+£µ-'`.
114
- And then your regex in the model file should look like that:
126
+ If you use `Devise` you might want to use the gem setup directly. And then your validator in the model file should look like that:
115
127
  ```erb
116
- /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#{Rails.application.config.allowed_special_chars}]).{#{Devise.password_length.first},#{Devise.password_length.last}}$/
128
+ is_right_length = Devise.password_length.include?(password.length)
117
129
  ```
118
130
  and the validator:
119
131
  ```erb
120
132
  validators: {
121
- length: Devise.password_length.first,
133
+ minlength: Devise.password_length.first,
134
+ maxlength: Devise.password_length.last,
122
135
  uppercase_char: true,
123
136
  lowercase_char: true,
124
137
  numeric_char: true,
125
- special_char: Rails.application.config.allowed_special_chars
138
+ special_char: true
126
139
  }
127
140
  ```
128
141
 
@@ -147,6 +160,18 @@ possible to help us in fixing the potential bug. We also encourage you to help e
147
160
 
148
161
  https://github.com/noesya/simple_form_password_with_hints/issues
149
162
 
163
+ ## Testing
164
+
165
+ ```shell
166
+ bundle install
167
+ cd test/dummy
168
+ bin/rails db:create db:migrate
169
+ bin/rails server
170
+ ````
171
+
172
+ Manual test on the page http://localhost:3000/users/sign_up
173
+
174
+
150
175
  ## Maintainers
151
176
 
152
177
  * Pierre-André Boissinot (https://github.com/pabois)
@@ -73,17 +73,37 @@ Element.prototype.parent = function (selector) {
73
73
 
74
74
  check: function (container, key, value) {
75
75
  var check = container.querySelector('.js-sfpwh-hint-' + key),
76
- regexKey,
77
- regex;
78
-
79
- if (check) {
80
- regexKey = this.getRegex(key, check);
81
- regex = new RegExp(regexKey);
82
- if (value.match(regex)) {
83
- check.classList.remove('sfpwh-hint--invalid');
84
- } else {
85
- check.classList.add('sfpwh-hint--invalid');
86
- }
76
+ valid = true;
77
+
78
+ if (!check) {
79
+ return
80
+ }
81
+
82
+ switch (key) {
83
+ case 'uppercase':
84
+ valid = new RegExp('[A-Z]').test(value);
85
+ break;
86
+ case 'lowercase':
87
+ valid = new RegExp('[a-z]').test(value);
88
+ break;
89
+ case 'number':
90
+ valid = new RegExp('[0-9]').test(value);
91
+ break;
92
+ case 'length':
93
+ var min = check.getAttribute('data-minlength'),
94
+ max = check.getAttribute('data-maxlength');
95
+ valid = value.length >= min && value.length <= max;
96
+ break;
97
+ case 'special':
98
+ valid = new RegExp('[^A-z0-9]').test(value);
99
+ default:
100
+ break;
101
+ }
102
+
103
+ if (valid) {
104
+ check.classList.remove('sfpwh-hint--invalid');
105
+ } else {
106
+ check.classList.add('sfpwh-hint--invalid');
87
107
  }
88
108
  },
89
109
 
@@ -117,38 +137,6 @@ Element.prototype.parent = function (selector) {
117
137
 
118
138
  input.type = input.type === 'text' ? 'password' : 'text';
119
139
  },
120
-
121
- // HELPERS
122
-
123
- getRegex: function (key, element) {
124
- var regex,
125
- min,
126
- chars;
127
-
128
- switch (key) {
129
- case 'uppercase':
130
- regex = '[A-Z]';
131
- break;
132
- case 'lowercase':
133
- regex = '[a-z]';
134
- break;
135
- case 'number':
136
- regex = '[0-9]';
137
- break;
138
- case 'special':
139
- // hyphen must be at the end
140
- chars = element.getAttribute('data-chars');
141
- regex = '[' + chars + ']';
142
- break;
143
- case 'length':
144
- min = element.getAttribute('data-length');
145
- regex = '.{' + min + ',128}';
146
- break;
147
- default:
148
- break;
149
- }
150
- return regex;
151
- }
152
140
  };
153
141
 
154
142
  if (document.readyState === 'complete' || document.readyState === 'interactive') {
@@ -1,6 +1,6 @@
1
1
  en:
2
2
  simple_form_password_with_hints:
3
- test_chars: "%{min_length} characters minimum"
3
+ test_chars: "Between %{min_length} and %{max_length} characters"
4
4
  test_uppercase: 'Uppercase'
5
5
  test_lowercase: 'Lowercase'
6
6
  test_numeric: 'Number'
@@ -1,6 +1,6 @@
1
1
  fr:
2
2
  simple_form_password_with_hints:
3
- test_chars: "%{min_length} caractères minimum"
3
+ test_chars: "Entre %{min_length} et %{max_length} caractères"
4
4
  test_uppercase: 'Majuscule'
5
5
  test_lowercase: 'Minuscule'
6
6
  test_numeric: 'Chiffre'
@@ -35,12 +35,19 @@ class PasswordWithHintsInput < ::SimpleForm::Inputs::Base
35
35
  end
36
36
 
37
37
  def length_div
38
- template.content_tag(
39
- :span,
40
- t('simple_form_password_with_hints.test_chars', min_length: options[:validators][:length]),
41
- data: { length: options[:validators][:length] },
42
- class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--length js-sfpwh-hint-length'
43
- ) if should_display?(:length)
38
+ # Retrocompatibility with the previous "length" param
39
+ if should_display?(:minlength) or should_display?(:length) then
40
+ minlength = options[:validators][:minlength] || options[:validators][:length]
41
+ # Retrocompatibility with the previous "maxlength" default value
42
+ maxlength = options[:validators][:maxlength] || 128
43
+
44
+ template.content_tag(
45
+ :span,
46
+ t('simple_form_password_with_hints.test_chars', min_length: minlength, max_length: maxlength),
47
+ data: { minlength:, maxlength: },
48
+ class: 'sfpwh-hint sfpwh-hint--invalid sfpwh-hint--length js-sfpwh-hint-length'
49
+ )
50
+ end
44
51
  end
45
52
 
46
53
  def uppercase_div
@@ -1,3 +1,3 @@
1
1
  module SimpleFormPasswordWithHints
2
- VERSION = "0.0.10".freeze
2
+ VERSION = "0.0.12".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_form_password_with_hints
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-andré Boissinot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-28 00:00:00.000000000 Z
11
+ date: 2026-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,7 +72,6 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
- - ".DS_Store"
76
75
  - ".eslintrc.yml"
77
76
  - ".gitignore"
78
77
  - ".sass-lint.yml"
data/.DS_Store DELETED
Binary file