Giter Club home page Giter Club logo

Comments (4)

bermi avatar bermi commented on June 30, 2024 2

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

from password-generator.

ADIOP55550 avatar ADIOP55550 commented on June 30, 2024

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

from password-generator.

fshields avatar fshields commented on June 30, 2024

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

from password-generator.

fshields avatar fshields commented on June 30, 2024

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.

from password-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.