@umituz/react-native-auth 3.5.12 → 3.5.13
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-auth",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.13",
|
|
4
4
|
"description": "Authentication service for React Native apps - Secure, type-safe, and production-ready. Provider-agnostic design with dependency injection, configurable validation, and comprehensive error handling.",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -34,39 +34,8 @@ describe('AuthPasswordValidation', () => {
|
|
|
34
34
|
expect(result.requirements.hasMinLength).toBe(false);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
it('should
|
|
38
|
-
const
|
|
39
|
-
expect(validatePasswordForRegister('password', configReq).isValid).toBe(false);
|
|
40
|
-
expect(validatePasswordForRegister('Password', configReq).requirements.hasUppercase).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should validate lowercase requirement', () => {
|
|
44
|
-
const configReq = { ...config, requireLowercase: true };
|
|
45
|
-
expect(validatePasswordForRegister('PASSWORD', configReq).isValid).toBe(false);
|
|
46
|
-
expect(validatePasswordForRegister('Password', configReq).requirements.hasLowercase).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should validate number requirement', () => {
|
|
50
|
-
const configReq = { ...config, requireNumber: true };
|
|
51
|
-
expect(validatePasswordForRegister('Password', configReq).isValid).toBe(false);
|
|
52
|
-
expect(validatePasswordForRegister('Password1', configReq).requirements.hasNumber).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should validate special character requirement', () => {
|
|
56
|
-
const configReq = { ...config, requireSpecialChar: true };
|
|
57
|
-
expect(validatePasswordForRegister('Password1', configReq).isValid).toBe(false);
|
|
58
|
-
expect(validatePasswordForRegister('Password1!', configReq).requirements.hasSpecialChar).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should accept password that meets all requirements', () => {
|
|
62
|
-
const strictConfig = {
|
|
63
|
-
...config,
|
|
64
|
-
requireUppercase: true,
|
|
65
|
-
requireLowercase: true,
|
|
66
|
-
requireNumber: true,
|
|
67
|
-
requireSpecialChar: true,
|
|
68
|
-
};
|
|
69
|
-
const result = validatePasswordForRegister('Password1!', strictConfig);
|
|
37
|
+
it('should accept password that meets length requirement', () => {
|
|
38
|
+
const result = validatePasswordForRegister('Password1!', config);
|
|
70
39
|
expect(result.isValid).toBe(true);
|
|
71
40
|
});
|
|
72
41
|
});
|
|
@@ -3,24 +3,16 @@ import type { PasswordConfig } from "../../domain/value-objects/AuthConfig";
|
|
|
3
3
|
export interface ValidationResult { isValid: boolean; error?: string; }
|
|
4
4
|
export interface PasswordStrengthResult extends ValidationResult { requirements: PasswordRequirements; }
|
|
5
5
|
export interface PasswordRequirements {
|
|
6
|
-
hasMinLength: boolean;
|
|
6
|
+
hasMinLength: boolean;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface ValidationConfig {
|
|
10
10
|
emailRegex: RegExp;
|
|
11
|
-
uppercaseRegex: RegExp;
|
|
12
|
-
lowercaseRegex: RegExp;
|
|
13
|
-
numberRegex: RegExp;
|
|
14
|
-
specialCharRegex: RegExp;
|
|
15
11
|
displayNameMinLength: number;
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
export const DEFAULT_VAL_CONFIG: ValidationConfig = {
|
|
19
15
|
emailRegex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
20
|
-
uppercaseRegex: /[A-Z]/,
|
|
21
|
-
lowercaseRegex: /[a-z]/,
|
|
22
|
-
numberRegex: /[0-9]/,
|
|
23
|
-
specialCharRegex: /[!@#$%^&*(),.?":{}|<>]/,
|
|
24
16
|
displayNameMinLength: 2,
|
|
25
17
|
};
|
|
26
18
|
|
|
@@ -41,28 +33,15 @@ export function validatePasswordForLogin(password: string): ValidationResult {
|
|
|
41
33
|
export function validatePasswordForRegister(
|
|
42
34
|
password: string,
|
|
43
35
|
config: PasswordConfig,
|
|
44
|
-
|
|
36
|
+
_validationConfig: ValidationConfig = DEFAULT_VAL_CONFIG
|
|
45
37
|
): PasswordStrengthResult {
|
|
46
|
-
/*
|
|
47
|
-
* Check for strict presence of characters regardless of configuration
|
|
48
|
-
* This ensures the UI reflects actual password content
|
|
49
|
-
*/
|
|
50
38
|
const req: PasswordRequirements = {
|
|
51
39
|
hasMinLength: password.length >= config.minLength,
|
|
52
|
-
hasUppercase: validationConfig.uppercaseRegex.test(password),
|
|
53
|
-
hasLowercase: validationConfig.lowercaseRegex.test(password),
|
|
54
|
-
hasNumber: validationConfig.numberRegex.test(password),
|
|
55
|
-
hasSpecialChar: validationConfig.specialCharRegex.test(password),
|
|
56
40
|
};
|
|
57
41
|
|
|
58
42
|
if (!password) return { isValid: false, error: "auth.validation.passwordRequired", requirements: req };
|
|
59
43
|
|
|
60
|
-
// Validation checks based on configuration
|
|
61
44
|
if (!req.hasMinLength) return { isValid: false, error: "auth.validation.passwordTooShort", requirements: req };
|
|
62
|
-
if (config.requireUppercase && !req.hasUppercase) return { isValid: false, error: "auth.validation.passwordRequireUppercase", requirements: req };
|
|
63
|
-
if (config.requireLowercase && !req.hasLowercase) return { isValid: false, error: "auth.validation.passwordRequireLowercase", requirements: req };
|
|
64
|
-
if (config.requireNumber && !req.hasNumber) return { isValid: false, error: "auth.validation.passwordRequireNumber", requirements: req };
|
|
65
|
-
if (config.requireSpecialChar && !req.hasSpecialChar) return { isValid: false, error: "auth.validation.passwordRequireSpecialChar", requirements: req };
|
|
66
45
|
|
|
67
46
|
return { isValid: true, requirements: req };
|
|
68
47
|
}
|
|
@@ -51,10 +51,6 @@ export const PasswordStrengthIndicator: React.FC<
|
|
|
51
51
|
|
|
52
52
|
const items = [
|
|
53
53
|
{ key: "minLength", label: t("auth.passwordReq.minLength"), isValid: requirements.hasMinLength },
|
|
54
|
-
{ key: "uppercase", label: t("auth.passwordReq.uppercase"), isValid: requirements.hasUppercase },
|
|
55
|
-
{ key: "lowercase", label: t("auth.passwordReq.lowercase"), isValid: requirements.hasLowercase },
|
|
56
|
-
{ key: "number", label: t("auth.passwordReq.number"), isValid: requirements.hasNumber },
|
|
57
|
-
{ key: "special", label: t("auth.passwordReq.special"), isValid: requirements.hasSpecialChar },
|
|
58
54
|
];
|
|
59
55
|
|
|
60
56
|
if (!showLabels) {
|
|
@@ -62,10 +62,6 @@ export function useRegisterForm(): UseRegisterFormResult {
|
|
|
62
62
|
if (!password) {
|
|
63
63
|
return {
|
|
64
64
|
hasMinLength: false,
|
|
65
|
-
hasUppercase: false,
|
|
66
|
-
hasLowercase: false,
|
|
67
|
-
hasNumber: false,
|
|
68
|
-
hasSpecialChar: false,
|
|
69
65
|
};
|
|
70
66
|
}
|
|
71
67
|
const result = validatePasswordForRegister(password, DEFAULT_PASSWORD_CONFIG);
|