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

Generator never hits uppercase 'A' #25

Closed
ADIOP55550 opened this issue Aug 7, 2019 · 4 comments
Closed

Generator never hits uppercase 'A' #25

ADIOP55550 opened this issue Aug 7, 2019 · 4 comments

Comments

@ADIOP55550
Copy link

I'm pretty sure that there is some kind of bug, that prevents capital A from appearing in passwords.
I've run this command: password-generator -c -l 50 -p "[a-zA-Z]" around 500 times and not a single 'A' appeared.

Here are some example results i ran into when I was examining this:

$ password-generator -c -l 50 -p "[Aa]"
> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ password-generator -c -l 50 -p "[Aab]"
> baaabbbababababababababaaabbabababbababbabaabbaaab
$ password-generator -c -l 50 -p "[AaBb]"
> bBbBBBbBBbbabaaBbbbaabBBaBBaababBBBaBbbBaBaBabBbbB
$ password-generator -c -l 50 -p "[BAa]"
> aaBaaaaBBaaBaBBaBBBBBBBBaaBaaaBBaBBBBBaBBaBaBaaaBa

Moreover, it also affects other capital letters if they're only one in the pattern:

$ password-generator -c -l 50 -p "[aBb]"
> aaaabbaabaabbbbbbaaaabaabbbbbaaabbbbbababaabaabbab
$ password-generator -c -l 50 -p "[a-zC]"
> urjxuxmsjxpcfnssijcwwlxikgxgeqchuqeliwtyqjrnzbqxvt
$ password-generator -c -l 50 -p "[a-zAB]"
> tvkobyiyBztramssvestxsagbmzohboebshxBnxxdnlwtkiomh
$ password-generator -c -l 50 -p "[a-zABC]"
> wCfkzoxicsxomhshdibfvtpBiuraisbdyaootuBeavboaypxdc

Also, giving it one letter as pattern generates "Maximum call stack size exceeded" error.
All those generate this error:
password-generator -c -l 50 -p "[A]"
password-generator -c -l 50 -p "A"
password-generator -c -l 50 -p "[a]"
password-generator -c -l 50 -p "a"

But that may be working as intended, because of required at least 2 characters in the pattern for some randomness.


And a screenshot from console:

Screen from console

@ADIOP55550 ADIOP55550 changed the title Generator never hits uppercse 'A' Generator never hits uppercase 'A' Aug 7, 2019
@ADIOP55550
Copy link
Author

There is a file containing result of 500 calls password-generator -c -l 50 -p "[a-zA-Z]". No 'A's!
result.txt

@fshields
Copy link

I've run into this issue as well. In fact, It happens even with digits. For example:
generatePassword(12, false, /\d/) will never generate a password with a zero in it (despite the README showing this as an example with a "0" in the output.)

I think I've discovered more about the issue. It seems that it is dropping the character with the lowest ASCII value from the list of character choices. So if you run this:
generatePassword(12, false, /AB5/) you will get a password with only "A" and "B" characters, but never a "5" because the character "5" has a lower ASCII value than any of the other characters.

ASCII Values:
"5" - decimal 53, hex 35
"A" - decimal 65, hex 41
"B" - decimal 66, hex 42

@fshields
Copy link

I'm pretty sure that the error lies in line 84 of /dist/password-generator.js:
if (value > min && value < max) {

The return from this function is used to select a character from a zero-based array. However, "value" can never be zero because "min" is zero; and 0 is not less than 0 (ever).

I think that line 84 should be changed to:
if (value >= min && value < max) {
so that the zero-ith element of the validChars[] array can be chosen.

@bermi
Copy link
Owner

bermi commented Nov 1, 2019

Thanks @ADIOP55550 for reporting this and @fshields for finding the solution to the bug. I was able to confirm it with a test case and pushed a fix to npm as 2.2.2

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

No branches or pull requests

3 participants