brendanashworth / generate-password

NodeJS library for generating cryptographically-secure passwords.
MIT License
354 stars 67 forks source link

Readme instructions are for synchronous code, but module appears to be acync #17

Closed jcreager closed 7 years ago

jcreager commented 7 years ago

Hi @brendanashworth

I hope this isn't a silly question. I am wondering if I am missing something in the readme for this module? It looks like the example code is synchronous:

var generator = require('generate-password');

var password = generator.generate({
    length: 10,
    numbers: true
});

// 'uEyMTw32v9' 
console.log(password);

However, console.log in this example returns undefined rather than the password. If I modify the code by passing a callback function as follows:

var generator = require('generate-password');

var password = generator.generate({
    length: 10,
    numbers: true
}, function (err, password) {
    console.log(password) //logs password to console
});

The password is logged to the console as expected rather than undefined.

I dug a little deeper and it looks like the self.generate method actually does return a callback:

    var password = generate(options, pool); //assign callback to var password

    return password; // return callback

That said, I do not see any open issues for your library pertaining to the issue that I have encountered. I am hoping to verify with you if I am missing something else, or if I am on the right track with this being an async module?

Thank you, Joe

brendanashworth commented 7 years ago

Hi @jcreager, apologies for the response time.

The module is entirely synchronous and doesn't offer an asynchronous option. One could be added in the future but as of right now, we only use sync methods and don't use any callbacks.

Sorry if that's confusing. I'll try and fix your confusion:

console.log in this example returns undefined

It will return undefined — it'll print the password to the console. password is where the value is.

The password is logged to the console as expected rather than undefined.

The module code doesn't support any async stuff, so that shouldn't — and doesn't — work. The function doesn't even accept a callback parameter.

self.generate method actually does return a callback

It does not. The inner generate will always return a string.

Did that clear it all up?