Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve the PIN Enter repetition validation rule and add relevant messages #1401

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

jian4on
Copy link
Contributor

@jian4on jian4on commented Jan 18, 2025

Summary of Changes

Change the PIN repetition validation to a number type rule 'max_repeated_numbers' to make the repeated-times validation setting more readable

Screenshots, videos, or gifs

N/A

Breaking change guide

The previous 'no_repeated_numbers' was an union type 'boolean | number', it is changed to a number and the rule name is changed too. The default validation setting was 'false' for allowing repeating, it is '5' for the new 'max_repeated_numbers' rule, so that repeating keep allowed for 6 digital PINs.
The validating behaviours are following the rule label exactly now, don't implement boolean value.
0: No adjacent numbers repeating allowed
n > 0: Maximum repeating times, e.g. '1 === n' for "11" allowed but "111" forbidden

Related Issues

N/A

Pull Request Checklist

Tick all boxes below to demonstrate that you have completed the respective task. If the item does not apply to your this PR check it anyway to make it apparent that there's nothing to do.

  • All commits contain a DCO Signed-off-by line (we use the DCO GitHub app to enforce this)
  • If applicable, screenshots, gifs, or video are included for UI changes
  • If applicable, breaking changes are described above along with how to address them
  • Updated documentation as needed for changed code and new or modified features
  • Added sufficient tests so that overall code coverage is not reduced

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

Pro Tip 🤓

  • Read our contribution guide at least once; it will save you a few review cycles!
  • Your PR will likely not be reviewed until all the above boxes are checked and all automated checks have passed

@jian4on jian4on requested a review from a team as a code owner January 18, 2025 18:28
@jian4on jian4on marked this pull request as draft January 18, 2025 18:29
@jian4on jian4on marked this pull request as ready for review January 20, 2025 14:58
@jian4on jian4on marked this pull request as draft January 20, 2025 18:24
@@ -71,7 +71,7 @@ export const PINRules: PINValidationRules = {
only_numbers: true,
min_length: 6,
max_length: 6,
no_repeated_numbers: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is in draft but if it's doable could we keep the defaults the same and just allow for opt-in behavior with the injectable PINSecurity.rules config we have currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put both PINSecurity and PINCreationValidation to IoC container, then the wallet variants can customize them without changinf Bifold default validating behavior. I will discuss with team. Thanks @bryce-mcmath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Back to default, but change the validating logic for '0' as 'repeating times' instead of its boolean value, keep the extra message for numbers repeating allowed but the repeating times exceeding the max times rule

Signed-off-by: Jian Wang <[email protected]>
…lidation message and change the logic of '0' in no_repeated_behavior

Signed-off-by: Jian Wang <[email protected]>
@jian4on jian4on changed the title feat: refactor the repetition rule in PINValidation and add relevant messages feat: improve the PIN Enter repetition validation rule and add relevant messages Jan 23, 2025
@jian4on jian4on marked this pull request as ready for review January 23, 2025 22:02
@jian4on jian4on requested a review from bryce-mcmath January 23, 2025 22:02
bryce-mcmath
bryce-mcmath previously approved these changes Jan 24, 2025
Copy link
Contributor

@bryce-mcmath bryce-mcmath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did have one question out of curiosity but it seems to still work either way. Nice going!

noRepeatedNumbers = new RegExp(`(\\d)\\1{${PINRules.no_repeated_numbers - 1},}`)
}

if ('number' === typeof(PINRules.no_repeated_numbers) && PINRules.no_repeated_numbers > 2 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would the > 2 check be needed at the same time as the string interpolation below is? Wouldn't there only be one case (3) where that condition is satisfied?

@@ -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,
no_repeated_numbers: true,
no_repeated_numbers: 0,
Copy link
Contributor

@jleach jleach Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no_ should be change to num_ if it now indicates the number of of repeating values allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jleach Good point, It is type 'boolean | number' now. I changed it to an enum [1,2,3,4 ...] type in the Draft version for discussing and then changed it back. Actually I still think maxRepetition number is an option.
@bryce-mcmath If you think we need more discussion, I will pull this feat back to draft

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jian4on ah right, the type changed. num is good I think, we can change the default since the type is changing. maybe just add a note in the "Breaking changes" section of the description of this PR so other teams know what to change to keep their existing behavior

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this will work well. There will be no way to disable the rule unless another flag is added. You can put in a high number but that will then be displayed during password selection, which would be confusing for the user.

…e rule 'max_repeated_numbers', and refactor the test cases relevently

Signed-off-by: Jian Wang <[email protected]>
Copy link

sonarqubecloud bot commented Feb 3, 2025

@jian4on jian4on marked this pull request as draft February 5, 2025 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants