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

Add numeric type #17

Merged
merged 3 commits into from
Jan 12, 2020
Merged

Conversation

thekevinbrown
Copy link
Contributor

@thekevinbrown thekevinbrown commented Jan 7, 2020

We would like to use this library to generate PIN numbers, which users must type on a numeric keypad (a separate hardware device). As it stands, we would need to use:

cryptoRandomString({ length: 4, characters: '0123456789' });

everywhere we do this.

My concern about this approach is it's easy to accidentally delete one character in the character set, and we'd end up with something like:

cryptoRandomString({ length: 4, characters: '012345789' });

Which at a glance you wouldn't notice is not actually the full numeric set and exponentially decreases the security of the generated PINs. I'd prefer to do:

cryptoRandomString({ length: 4, type: 'numeric' });

As this seems more readable to me, as well as throwing an error at runtime if it's subtly broken instead of just silently becoming less secure. We also use Typescript, so we'd see the error in the type option immediately as well.

Edit: I also fixed a typo in a comment, forgot to mention that.

@sindresorhus sindresorhus changed the title Added numeric type, fixed typo in comment. Add numeric type Jan 12, 2020
@sindresorhus sindresorhus merged commit 1ebdf2e into sindresorhus:master Jan 12, 2020
@sindresorhus
Copy link
Owner

Makes sense. Thanks for the PR. 👍

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.

2 participants