use-password-policy 1.0.2 → 1.0.4

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/README.md +75 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ ## usePasswordPolicy Hook
2
+
3
+ This React hook simplifies password policy enforcement in your application. It provides a flexible and customizable way to validate passwords against various criteria, ensuring strong password security.
4
+
5
+ Features:
6
+ - Built-in Policies: Enforces common password complexity requirements like minimum length, case sensitivity, digit inclusion, and special characters.
7
+
8
+ - Custom Policies: Define your own validation checks using regular expressions or custom functions for even more granular control.
9
+
10
+ - Configurable Defaults: Specify a default configuration for common policies, or override them with custom settings.
11
+
12
+ Installation:
13
+
14
+ ```
15
+ npm install use-password-policy
16
+ ```
17
+
18
+ Usage:
19
+
20
+ ```javascript
21
+
22
+ import { usePasswordPolicy } from './use-password-policy';
23
+ function MyComponent() {
24
+ const [password, setPassword] = useState('');
25
+ const policy = usePasswordPolicy({
26
+ password,
27
+ config: { minLength: 12 },
28
+ customPolicies: [{ name: 'noRepeatedChars', regex: /^(?!.*(.)\1)/ },],});
29
+ const isPasswordValid = Object.values(policy).every(check => check);
30
+
31
+ return (
32
+ <form>
33
+ <input
34
+ type="password"
35
+ value={password}
36
+ onChange={e => setPassword(e.target.value)}
37
+ />
38
+ {isPasswordValid ? (
39
+ <p>Password is strong!</p>
40
+ ) : (
41
+ <ul>
42
+ {Object.entries(policy).map(([key, value]) => (
43
+ <li key={key}>{!value && key.replace(/([A-Z])/g, ' $1')}</li>
44
+ ))}
45
+ </ul>
46
+ )}
47
+ </form>
48
+ );
49
+ }
50
+ ```
51
+
52
+ **Props:**
53
+
54
+ | Prop Name | Type | Description | Default Value |
55
+ | ---------------------- | --------------------------- | ------------------------------------------------------------------------------------------ | -------------------------- |
56
+ | `password` | string | The password to be validated. | Required |
57
+ | `config` | object (optional) | An object overriding default configuration for built-in policies. | |
58
+ | - `minLength` | number | Minimum password length | 8 |
59
+ | - `uppercaseCharRegex` | RegExp | Regular expression for uppercase characters | /[A-Z]/ |
60
+ | - `digitRegex` | RegExp | Regular expression for digits | /\d/ |
61
+ | - `specialCharRegex` | RegExp | Regular expression for special characters | /[!@#$%^&*()_+-=[]{};':"\| |
62
+ | `customPolicies` | array of objects (optional) | An array of custom policies to enforce. | |
63
+ | - `name` | string | Name of the custom policy for clarity in feedback. | |
64
+ | - `regex` | RegExp (optional) | Regular expression for custom validation. | |
65
+ | - `checkFunction` | function (optional) | A function taking the password as an argument and returning true/false for a custom check. | |
66
+
67
+ **Return Value:**
68
+
69
+ An object containing boolean values for each policy check (built-in and custom). Use `Object.values(policy).every(check => check)` to determine if all policies are satisfied.
70
+
71
+ **Benefits:**
72
+
73
+ - **Improved Security:** Enforces strong passwords, reducing the risk of brute-force attacks and data breaches.
74
+ - **Enhanced User Experience:** Provides clear feedback to users on password strength, guiding them towards creating secure passwords.
75
+ - **Customization:** Adapts to your specific security requirements through configurable defaults and custom policies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "use-password-policy",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "use-password-policy.ts",
6
6
  "scripts": {