diff --git a/packages/legacy/core/App/constants.ts b/packages/legacy/core/App/constants.ts index c09b6147d..852119502 100644 --- a/packages/legacy/core/App/constants.ts +++ b/packages/legacy/core/App/constants.ts @@ -71,7 +71,7 @@ export const PINRules: PINValidationRules = { only_numbers: true, min_length: 6, max_length: 6, - no_repeated_numbers: false, + max_repeated_numbers: 5, no_repetition_of_the_two_same_numbers: false, no_series_of_numbers: false, no_even_or_odd_series_of_numbers: false, diff --git a/packages/legacy/core/App/types/security.ts b/packages/legacy/core/App/types/security.ts index a13ef0675..e2342dc61 100644 --- a/packages/legacy/core/App/types/security.ts +++ b/packages/legacy/core/App/types/security.ts @@ -11,16 +11,15 @@ export enum AuthLevel { } /* - no_repeated_numbers - forbid adjacent numbers repeating or not, and specify the forbidden repeating times when repeating allowed - true | 0 | 1 | 2: forbid adjacent numbers repetition - false: no check for adjacent numbers repeating - other numbers: the length of adjacent repeating numbers is forbidden, e.g. '3' will forbid 055567, but 055678 is allowed + max_repeated_numbers - adjacent characters allowed repeating times + 0 - Forbid adjacent characters repeating + n > 0 - permit repeating times, e.g. '1 === n' for '11' permitted but '111' forbidden */ export interface PINValidationRules { only_numbers: boolean min_length: number max_length: number - no_repeated_numbers: boolean | number + max_repeated_numbers: number no_repetition_of_the_two_same_numbers: boolean | number no_series_of_numbers: boolean no_even_or_odd_series_of_numbers: boolean diff --git a/packages/legacy/core/App/utils/PINCreationValidation.ts b/packages/legacy/core/App/utils/PINCreationValidation.ts index f1e56db18..08ceaf837 100644 --- a/packages/legacy/core/App/utils/PINCreationValidation.ts +++ b/packages/legacy/core/App/utils/PINCreationValidation.ts @@ -39,17 +39,17 @@ export const PINCreationValidations = (PIN: string, PINRules: PINValidationRules } as PINValidationsType) } - if ('number' === typeof(PINRules.no_repeated_numbers) && PINRules.no_repeated_numbers > 2 ) { - const repetitionPattern = new RegExp(String.raw`(\d)\1{${PINRules.no_repeated_numbers - 1},}`, "g") + if (0 === PINRules.max_repeated_numbers) { + const repetitionPattern = new RegExp(/(\d)\1{1,}/) PINValidations.push({ isInvalid: repetitionPattern.test(PIN), - errorName: PINError.MaxAdjacentNumberRepetitionValidation + errorName: PINError.NoRepetitionOfTheSameNumbersValidation } as PINValidationsType) - } else if (PINRules.no_repeated_numbers || 0 === PINRules.no_repeated_numbers) { - const repetitionPattern = new RegExp(/(\d)\1{1,}/) + } else { + const repetitionPattern = new RegExp(String.raw`(\d)\1{${PINRules.max_repeated_numbers + 1},}`, "g") PINValidations.push({ isInvalid: repetitionPattern.test(PIN), - errorName: PINError.NoRepetitionOfTheSameNumbersValidation + errorName: PINError.MaxAdjacentNumberRepetitionValidation } as PINValidationsType) } diff --git a/packages/legacy/core/__tests__/utils/PINCreationValidation.test.ts b/packages/legacy/core/__tests__/utils/PINCreationValidation.test.ts index 79513d5f7..1cb3842a4 100644 --- a/packages/legacy/core/__tests__/utils/PINCreationValidation.test.ts +++ b/packages/legacy/core/__tests__/utils/PINCreationValidation.test.ts @@ -4,7 +4,7 @@ const defaultPINRules = { only_numbers: false, min_length: 6, max_length: 6, - no_repeated_numbers: false, + max_repeated_numbers: 5, no_series_of_numbers: false, no_repetition_of_the_two_same_numbers: false, no_even_or_odd_series_of_numbers: false, @@ -74,10 +74,10 @@ describe('PIN creation validations', () => { } }) - test('PIN with repeated numbers and repeated numbers validation to true, so the validation use the default of two repeated numbers, should return NoRepetitionOfTheSameNumbersValidation as invalid', async () => { + test('PIN with repeated numbers and max repeated numbers is 0, should return NoRepetitionOfTheSameNumbersValidation as invalid', async () => { const PINRulesWithRepeatedNumbers = { ...defaultPINRules, - no_repeated_numbers: 0, + max_repeated_numbers: 0, } const PINWithRepeatedNumbers = '113456' @@ -90,10 +90,10 @@ describe('PIN creation validations', () => { } }) - test('PIN with repeated numbers and repeated numbers validation to a number, so the validation use that number as validation limit, should return NoRepetitionOfTheSameNumbersValidation as invalid', async () => { + test('PIN with adhacent numbers repeating 2 times and max repeated numbers is 1, so the validation use that number as validation max limit, should return NoRepetitionOfTheSameNumbersValidation as invalid', async () => { const PINRulesWithRepeatedNumbers = { ...defaultPINRules, - no_repeated_numbers: 3, + max_repeated_numbers: 1, } const PINWithRepeatedNumbers = '111456' @@ -106,13 +106,13 @@ describe('PIN creation validations', () => { } }) - test('PIN with a numbers repeated two times and repeated numbers validation set to 3 should return NoRepetitionOfTheSameNumbersValidation as valid', async () => { + test('PIN with adhacent numbers repeating 2 times and max repeated numbers is 2, so the validation use that number as validation max limit, should return NoRepetitionOfTheSameNumbersValidation as valid', async () => { const PINRulesWithRepeatedNumbers = { ...defaultPINRules, - no_repeated_numbers: 3, + max_repeated_numbers: 2, } - const PINWithRepeatedNumbers = '112456' + const PINWithRepeatedNumbers = '111456' const PINValidations = PINCreationValidations(PINWithRepeatedNumbers, PINRulesWithRepeatedNumbers) for (const PINValidation of PINValidations) {