Skip to content

Commit

Permalink
Restore the default no_repeated_numbers behavior, but keep the new va…
Browse files Browse the repository at this point in the history
…lidation message and change the logic of '0' in no_repeated_behavior

Signed-off-by: Jian Wang <[email protected]>
  • Loading branch information
jian4on committed Jan 22, 2025
1 parent 354f500 commit bafa89c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/legacy/core/App/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const PINRules: PINValidationRules = {
only_numbers: true,
min_length: 6,
max_length: 6,
max_repeated_numbers: 1,
no_repeated_numbers: false,
no_repetition_of_the_two_same_numbers: false,
no_series_of_numbers: false,
no_even_or_odd_series_of_numbers: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/core/App/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const translation = {
"CrossPatternValidation": "A pattern of cross was detected in your PIN. Please try again.",
"OddOrEvenSequenceValidation": "An odd or even sequence was detected in your PIN. Please try again.",
"NoRepetitionOfTheSameNumbersValidation": "The PIN can't have a repetition of the same digit. Please try again.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again.",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again.",
"NoRepetitionOfTheTwoSameNumbersValidation": "A repeated two-digit sequence was detected in your PIN. Please try again.",
"NoSeriesOfNumbersValidation": "A series was detected in your PIN. Please try again.",
"PINOnlyContainDigitsValidation": "Your PIN needs to only contain digits. Please try again.",
Expand All @@ -218,7 +218,7 @@ const translation = {
"CrossPatternValidation": "Does not contain a pattern of cross.",
"OddOrEvenSequenceValidation": "Does not contain an odd or even sequence.",
"NoRepetitionOfTheSameNumbersValidation": "Does not contain the same repeating number.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are limited.",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are limited.",
"NoRepetitionOfTheTwoSameNumbersValidation": "Does not contain repeating two-digit sequence.",
"NoSeriesOfNumbersValidation": "Does not contain a series of numbers (123).",
"PINOnlyContainDigitsValidation": "Must contain only digits.",
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/core/App/localization/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const translation = {
"Message": {
"CrossPatternValidation": "Un patron de croix a été détecté dans votre NIP. Veuillez saisir un NIP différent.",
"OddOrEvenSequenceValidation": "Une séquence impaire ou paire a été détectée dans votre NIP. Veuillez saisir un NIP différent.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again. (FR)",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again. (FR)",
"NoRepetitionOfTheTwoSameNumbersValidation": "Une séquence de deux chiffres répétée a été détectée dans votre NIP. Veuillez saisir un NIP différent.",
"NoRepetitionOfTheSameNumbersValidation": "Votre NIP contient une répétition. Choisissez un NIP différent.",
"NoSeriesOfNumbersValidation": "Une suite a été détectée dans votre NIP. Veuillez saisir un NIP différent.",
Expand All @@ -216,7 +216,7 @@ const translation = {
"Helper": {
"CrossPatternValidation": "Ne doit pas contenir un patron de croix.",
"OddOrEvenSequenceValidation": "Ne doit pas contenir une suite paire ou impaire.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are limited. (FR)",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are limited. (FR)",
"NoRepetitionOfTheTwoSameNumbersValidation": "Ne doit pas contenir deux chiffres qui se répètent.",
"NoRepetitionOfTheSameNumbersValidation": "Ne doit pas contenir de répétition.",
"NoSeriesOfNumbersValidation": "Ne doit pas contenir de suite (123).",
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy/core/App/localization/pt-br/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const translation = {
"CrossPatternValidation": "Um padrão de X foi detectado no seu PIN. Favor tentar novamente.",
"OddOrEvenSequenceValidation": "Uma sequencia de números pares ou ímpares foi detectada em seu PIN. Favor tentar novamente.",
"NoRepetitionOfTheSameNumbersValidation": "O PIN não pode ter a repetição de um mesmo número. Favor tentar novamente.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again. (PT-BR)",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are more than allowed. Please try again. (PT-BR)",
"NoRepetitionOfTheTwoSameNumbersValidation": "Uma sequência repetida de dois números foi detectada em seu PIN. Favor tentar novamente.",
"NoSeriesOfNumbersValidation": "Uma sequência foi detectada em seu PIN. Favor tentar novamente.",
"PINOnlyContainDigitsValidation": "Seu PIN deve conter apenas números. Favor tentar novamente.",
Expand All @@ -211,7 +211,7 @@ const translation = {
"CrossPatternValidation": "Não contém um padrão de X.",
"OddOrEvenSequenceValidation": "Não contém uma sequência de números pares ou ímpares.",
"NoRepetitionOfTheSameNumbersValidation": "Não contém o mesmo número repetido.",
"MaxAdjacentBumberRepetitionValidation": "Adjacent numbers repeating times are limited. (PT-BR)",
"MaxAdjacentNumberRepetitionValidation": "Adjacent numbers repeating times are limited. (PT-BR)",
"NoRepetitionOfTheTwoSameNumbersValidation": "Não contém uma sequência repetida de dois números.",
"NoSeriesOfNumbersValidation": "Não contém uma sequência de números (123).",
"PINOnlyContainDigitsValidation": "Deve conter apenas números.",
Expand Down
9 changes: 5 additions & 4 deletions packages/legacy/core/App/types/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ export enum AuthLevel {
}

/*
max_repeated_numbers - max repeating times in adjacent PIN numbers
0 (including undefined or NaN): Repetition is not allowed
i > 0: adjacent max repeating number times, e.g. number '5' repeating 2 times in '055234'
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
*/
export interface PINValidationRules {
only_numbers: boolean
min_length: number
max_length: number
max_repeated_numbers: number
no_repeated_numbers: boolean | number
no_repetition_of_the_two_same_numbers: boolean | number
no_series_of_numbers: boolean
no_even_or_odd_series_of_numbers: boolean
Expand Down
31 changes: 11 additions & 20 deletions packages/legacy/core/App/utils/PINCreationValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,11 @@ const oddNumberSeries = new RegExp('(02468)')
const isNumber = new RegExp('^[0-9]+$')
const crossNumberPattern = ['159753', '159357', '951357', '951753', '357159', '357951', '753159', '753951']

const maxRepetition = (select: number) => {
if (2 > select) {
return new RegExp(/(\d)\1{1,}/)
} else {
return new RegExp(String.raw`(\d)\1{${select},}`, "g")
}
}
const repetitionErrorMessage = (select: number) => {
if (2 > select) {
return PINError.NoRepetitionOfTheSameNumbersValidation
} else {
return PINError.MaxAdjacentBumberRepetitionValidation
}
}

export enum PINError {
CrossPatternValidation = 'CrossPatternValidation',
OddOrEvenSequenceValidation = 'OddOrEvenSequenceValidation',
NoRepetitionOfTheSameNumbersValidation = 'NoRepetitionOfTheSameNumbersValidation',
MaxAdjacentBumberRepetitionValidation = 'MaxAdjacentBumberRepetitionValidation',
MaxAdjacentNumberRepetitionValidation = 'MaxAdjacentNumberRepetitionValidation',
NoRepetitionOfTheTwoSameNumbersValidation = 'NoRepetitionOfTheTwoSameNumbersValidation',
NoSeriesOfNumbersValidation = 'NoSeriesOfNumbersValidation',
PINOnlyContainDigitsValidation = 'PINOnlyContainDigitsValidation',
Expand Down Expand Up @@ -54,11 +39,17 @@ export const PINCreationValidations = (PIN: string, PINRules: PINValidationRules
} as PINValidationsType)
}

if (PINRules.max_repeated_numbers || 0 === PINRules.max_repeated_numbers) {
const noRepeatedNumbers = maxRepetition(PINRules.max_repeated_numbers)
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")
PINValidations.push({
isInvalid: repetitionPattern.test(PIN),
errorName: PINError.MaxAdjacentNumberRepetitionValidation
} as PINValidationsType)
} else if (PINRules.no_repeated_numbers || 0 === PINRules.no_repeated_numbers) {
const repetitionPattern = new RegExp(/(\d)\1{1,}/)
PINValidations.push({
isInvalid: noRepeatedNumbers.test(PIN),
errorName: repetitionErrorMessage(PINRules.max_repeated_numbers)
isInvalid: repetitionPattern.test(PIN),
errorName: PINError.NoRepetitionOfTheSameNumbersValidation
} as PINValidationsType)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultPINRules = {
only_numbers: false,
min_length: 6,
max_length: 6,
max_repeated_numbers: 1,
no_repeated_numbers: false,
no_series_of_numbers: false,
no_repetition_of_the_two_same_numbers: false,
no_even_or_odd_series_of_numbers: false,
Expand Down Expand Up @@ -77,7 +77,7 @@ 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 () => {
const PINRulesWithRepeatedNumbers = {
...defaultPINRules,
max_repeated_numbers: 0,
no_repeated_numbers: 0,
}

const PINWithRepeatedNumbers = '113456'
Expand All @@ -93,7 +93,7 @@ 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 () => {
const PINRulesWithRepeatedNumbers = {
...defaultPINRules,
max_repeated_numbers: 3,
no_repeated_numbers: 3,
}

const PINWithRepeatedNumbers = '111456'
Expand All @@ -109,7 +109,7 @@ 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 () => {
const PINRulesWithRepeatedNumbers = {
...defaultPINRules,
max_repeated_numbers: 3,
no_repeated_numbers: 3,
}

const PINWithRepeatedNumbers = '112456'
Expand Down

0 comments on commit bafa89c

Please sign in to comment.