use-password-policy 1.0.0 → 1.0.2
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.
- package/Type.ts +10 -0
- package/package.json +1 -1
- package/use-password-policy.ts +4 -3
package/Type.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface CustomPolicy {
|
|
2
|
+
name: string; // Name of the policy (e.g., "SymbolCheck")
|
|
3
|
+
regex?: RegExp; // Regular expression for the check (optional)
|
|
4
|
+
checkFunction?: (password: string) => boolean; // Custom check function (optional)
|
|
5
|
+
message?: string; // Error message if the check fails (optional)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface StateObjects {
|
|
9
|
+
[key: string]: boolean;
|
|
10
|
+
}
|
package/package.json
CHANGED
package/use-password-policy.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect, useMemo } from "react";
|
|
2
|
-
import { CustomPolicy } from "
|
|
2
|
+
import { CustomPolicy, StateObjects } from "./Type";
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
export const usePasswordPolicy = ({
|
|
5
6
|
password,
|
|
@@ -33,7 +34,7 @@ export const usePasswordPolicy = ({
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const [policy, setPolicy] = useState<
|
|
37
|
+
const [policy, setPolicy] = useState<StateObjects>(() => {
|
|
37
38
|
if (useDefaultConfig) {
|
|
38
39
|
return {
|
|
39
40
|
caseCheck: false,
|
|
@@ -62,7 +63,7 @@ export const usePasswordPolicy = ({
|
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
const evaluateChecks = () => {
|
|
65
|
-
const newPolicy:
|
|
66
|
+
const newPolicy: StateObjects = { ...policy };
|
|
66
67
|
if (useDefaultConfig) {
|
|
67
68
|
newPolicy.caseCheck =
|
|
68
69
|
merged.caseCheck && RegExp(merged.uppercaseCharRegex).test(password);
|