@osimatic/helpers-js 1.3.1 → 1.3.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/user.js +63 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/user.js CHANGED
@@ -13,23 +13,73 @@ class Password {
13
13
  return score;
14
14
  }
15
15
 
16
- static updatePasswordStrengthUI(div, password) {
17
- const score = Password.getPasswordStrength(password);
16
+ static displayPasswordStrength(input) {
17
+ function update(input) {
18
+ input = $(input);
19
+ const password = input.val();
20
+ const div = input.closest('.form-group').find('.password_strength_content');
21
+ const score = Password.getPasswordStrength(password);
18
22
 
19
- const strengthBar = div.find('.password_strength_bar');
20
- const strengthText = div.find('.password_strength_text');
23
+ const strengthBar = div.find('.password_strength_bar');
24
+ const strengthText = div.find('.password_strength_text');
21
25
 
22
- let width = (score / 6) * 100;
23
- let color = 'bg-danger';
24
- let text = 'Très faible';
26
+ const conditions = {
27
+ length: password.length >= 8,
28
+ uppercase: /[A-Z]/.test(password),
29
+ lowercase: /[a-z]/.test(password),
30
+ number: /[0-9]/.test(password),
31
+ special: /[^A-Za-z0-9]/.test(password),
32
+ };
25
33
 
26
- if (score >= 2) { color = 'bg-warning'; text = 'Faible'; }
27
- if (score >= 4) { color = 'bg-info'; text = 'Moyen'; }
28
- if (score >= 5) { color = 'bg-success'; text = 'Fort'; }
34
+ // Mise à jour des conditions
35
+ div.find('.password_strength_conditions li').each(function () {
36
+ const cond = $(this).data('condition');
37
+ $(this).removeClass('text-success text-danger');
38
+ if (conditions[cond]) {
39
+ $(this).addClass('text-success');
40
+ } else {
41
+ $(this).addClass('text-danger');
42
+ }
43
+ });
29
44
 
30
- strengthBar.className = `progress-bar ${color}`;
31
- strengthBar.style.width = `${width}%`;
32
- strengthText.textContent = text;
45
+ let width = (score / 6) * 100;
46
+ let color = 'danger';
47
+ let text = 'Très faible';
48
+
49
+ if (score >= 2) { color = 'danger'; text = 'Faible'; }
50
+ if (score >= 4) { color = 'warning'; text = 'Moyen'; }
51
+ if (score >= 5) { color = 'success'; text = 'Fort'; }
52
+
53
+ strengthBar.removeClass('bg-danger bg-warning bg-success').addClass('bg-'+color);
54
+ strengthText.removeClass('text-bg-danger text-bg-warning text-bg-success hide').addClass(password === '' ? 'hide' : 'text-bg-'+color);
55
+ strengthBar.width(width+'%');
56
+ strengthText.text(text);
57
+ }
58
+
59
+ const formGroup = input.closest('.form-group');
60
+ formGroup.find('.password_strength_content').remove();
61
+ formGroup.append(''
62
+ +'<div class="password_strength_content mt-1">'
63
+ +' <div class="progress" style="height: 6px;">'
64
+ +' <div class="password_strength_bar progress-bar" role="progressbar"></div>'
65
+ +' </div>'
66
+ +' <div class="d-flex justify-content-between align-items-start mt-2">'
67
+ +' <ul class="password_strength_conditions mb-0 ps-0" style="list-style: none;">'
68
+ +' <li data-condition="length">✔ Au moins 8 caractères</li>'
69
+ +' <li data-condition="uppercase">✔ Une majuscule</li>'
70
+ +' <li data-condition="lowercase">✔ Une minuscule</li>'
71
+ +' <li data-condition="number">✔ Un chiffre</li>'
72
+ +' <li data-condition="special">✔ Un caractère spécial</li>'
73
+ +' </ul>'
74
+ +' <div class="ms-3 text-end">'
75
+ +' <span class="badge password_strength_text" style="font-size: 10pt; font-weight: normal">New</span>'
76
+ +' </div>'
77
+ +' </div>'
78
+ +'</div>'
79
+ );
80
+ input.change(() => update(input));
81
+ input.on('input', () => update(input));
82
+ update(input);
33
83
  }
34
84
  }
35
85