Giter Site home page Giter Site logo

bcrypt-nodejs's Introduction

Note: This project is not actively maintained

If you are looking for a javscript-only bcrypt implementation we recommend you use bcrypt.js, which is based on bcrypt-nodejs.

bcrypt-nodejs

===========================================

Join the chat at https://gitter.im/shaneGirish/bcrypt-nodejs Build Status Dependency Status

Warning : A change was made in v0.0.3 to allow encoding of UTF-8 encoded strings. This causes strings encoded in v0.0.2 or earlier to not work in v0.0.3 anymore.

Native JS implementation of BCrypt for Node. Has the same functionality as node.bcrypt.js expect for a few tiny differences. Mainly, it doesn't let you set the seed length for creating the random byte array.

I created this version due to a small problem I faced with node.bcrypt.js. Basically, to deploy one of my apps which uses node.bcrypt.js on a winx64 platform, I have to force the user to download about 1.6gb of sdks, buildtools and other requirements of which some fail to install ! Microsoft :(

This code is based on javascript-bcrypt and uses crypto to create random byte arrays.

Basic usage:

Installing the Package

npm install bcrypt-nodejs or yarn add bcrypt-nodejs

Synchronous

var hash = bcrypt.hashSync("bacon");

bcrypt.compareSync("bacon", hash); // true
bcrypt.compareSync("veggies", hash); // false

Asynchronous

bcrypt.hash("bacon", null, null, function(err, hash) {
  // Store hash in your password DB.
});

// Load hash from your password DB.
bcrypt.compare("bacon", hash, function(err, res) {
    // res == true
});
bcrypt.compare("veggies", hash, function(err, res) {
    // res = false
});

In the above examples, the salt is automatically generated and attached to the hash. Though you can use your custom salt and there is no need for salts to be persisted as it will always be included in the final hash result and can be retrieved.

API

  • genSaltSync(rounds)
    • rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
  • genSalt(rounds, callback)
    • rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
    • callback - [REQUIRED] - a callback to be fired once the salt has been generated.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing the generated salt.
  • hashSync(data, salt)
    • data - [REQUIRED] - the data to be encrypted.
    • salt - [REQUIRED] - the salt to be used in encryption.
  • hash(data, salt, progress, cb)
    • data - [REQUIRED] - the data to be encrypted.
    • salt - [REQUIRED] - the salt to be used to hash the password.
    • progress - a callback to be called during the hash calculation to signify progress
    • callback - [REQUIRED] - a callback to be fired once the data has been encrypted.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing the encrypted form.
  • compareSync(data, encrypted)
    • data - [REQUIRED] - data to compare.
    • encrypted - [REQUIRED] - data to be compared to.
  • compare(data, encrypted, cb)
    • data - [REQUIRED] - data to compare.
    • encrypted - [REQUIRED] - data to be compared to.
    • callback - [REQUIRED] - a callback to be fired once the data has been compared.
      • error - First parameter to the callback detailing any errors.
      • result - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
  • getRounds(encrypted) - return the number of rounds used to encrypt a given hash
    • encrypted - [REQUIRED] - hash from which the number of rounds used should be extracted.

Contributors

Credits

I heavily reused code from javascript-bcrypt. Though "Clipperz Javascript Crypto Library" was removed and its functionality replaced with crypto.

bcrypt-nodejs's People

Contributors

ajcrites avatar alexmurray avatar amos47 avatar andrejewski avatar fpirsch avatar gitter-badger avatar joshball avatar karliatto avatar nisaacson avatar peteratticusberg avatar phanect avatar shanemangudi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bcrypt-nodejs's Issues

Not a valid BCrypt hash.

I am using this with Angular 1.5 + nodeJS + mysql.

Following is code to store password in database:

 var newUserMysql = {
                            firstname: req.body.fname,
                            lastname: req.body.lname,
                            username: username,
                            password: bcrypt.hashSync(password),
                            createdDateTime : new Date()
                        };

                        var insertQuery = "INSERT INTO users ( FirstName,LastName,Email, Password,CreatedDateTime ) values (?,?,?,?,?)";

                        connection.query(insertQuery, [newUserMysql.firstname,newUserMysql.lastname,newUserMysql.username, newUserMysql.password,newUserMysql.createdDateTime], function (err, rows) {
                            newUserMysql.id = rows.insertId;
                            return done(null, newUserMysql);
                        });

it is saving data correctly. Now while login I am trying to compare password with following code, I am getting error of

C:\Users\SONY.ssh\KoruLife\node_modules\mysql\lib\protocol\Parser.js:79
throw err; // Rethrow non-MySQL errors
^
Not a valid BCrypt hash.

Code for Login :

 passport.use(
        'local-login',
        new LocalStrategy({
                // by default, local strategy uses username and password, we will override with email
                usernameField: 'username',
                passwordField: 'password',
                passReqToCallback
passport.use(
        'local-login',
        new LocalStrategy({
                // by default, local strategy uses username and password, we will override with email
                usernameField: 'username',
                passwordField: 'password',
                passReqToCallback: true // allows us to pass back the entire request to the callback
            },
            function (req, username, password, done) { // callback with email and password from our form
                connection.query("SELECT * FROM users WHERE email = ?", [username], function (err, rows) {
                    if (err)
                        return done(err);
                    if (!rows.length) {
                        return done(null,false); // req.flash is the way to set flashdata using connect-flash
                    }
                    //var pwd = bcrypt.hashSync(password, null, null);
                    if(!bcrypt.compareSync(password, rows[0].Password)){
                        return done(null,false);
                    }
                    return done(null, rows[0]);
                });
            })
    );

[Compatibility] Passing a number as salt parameter doesn't work

From node.bcrypt.js documentation:

salt - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated and used (see examples).

If I do this in bcrypt-nodejs, I get

TypeError: Object 1 has no method 'charAt'

package.json license field

Many people use tooling to discover what NPM module licenses they depend on. This tooling typically uses the license field in package.json. Could you maybe fill that in? I'd have sent a PR but I can't tell which SPDX license ID your license file should be.

expected speed

Folks,
The following function call takes roughly 80msecs to execute and return.

    var timeStart = _.now();
    bcrypt.compare(req.body.password, userObject.password, function(err, result) {
        var appTime = _.now() - timeStart;
        console.log('bcrypt compare',appTime);
        callback();
    });

console:

bcrypt compare 92

Expected behavior? I've read here http://stackoverflow.com/questions/15763086/bcrypt-for-password-hashing-because-it-is-slow , and from what I understand this isnt all that harmful to an auth service. 100msecs is OK to expect for authentication, but will make an attacker's job more difficult.

Thoughts?

Thanks!

default seed_length

noobie question:

it is said that the seed_length. (default - 20)

Is seed_length the same as BCRYPT_SALT_LEN?

At the top of the file there is this:
var BCRYPT_SALT_LEN = 16;

Any Decryption Method?

I'm still new to this encryption methodology. Is there any method I can decrypt the encrypted data ?

Callback required error when hashing with 3 params

The hash function checks for the existence of a given callback function (4th function parameter), and has progress as a 3rd parameter. But it doesn't check if only 3 params are given. In that case it should assume that the 3rd parameter is the actual callback. This would make it compatible with bcrypt.

Bug with 31 rounds ?

I can barely compute a hash when the number of rounds approaches 20.
With 30 rounds my desktop freezes. So far it's OK, bcrypt is supposed to be CPU-intensive.
But surprisingly with 31 rounds I get a hash almost instantly.

Comparing $2y$ hashes

I have some hashes in my database which were previously created with PHP's bcrypt function.

If I try to run bcrypt.compareSync with the PHP's $2y$ versioned hash, it errors with "Invalid salt revision". Would it be possible to support $2y$ hashes instead of just $2a$?

Error while installing

I use Windows 7. Here is my error:

D:\alles\Documents_tellize\feed>npm install
npm WARN package.json [email protected] path is also the name of a node core module.

[email protected] install D:\alles\Documents_tellize\feed\node_modules\bcrypt
node-gyp rebuild

D:\alles\Documents_tellize\feed\node_modules\bcrypt>node "C:\Program Files (x86
)\nodejs\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node
-gyp.js" rebuild
child_process: customFds option is deprecated, use stdio instead.
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
MSBUILD : error MSB3411: Die Visual C++-Komponente "VCBuild.exe" konnte nicht g
eladen werden. Wenn die Komponente installiert ist, fügen Sie deren Speicherort
dem Systempfad hinzu. Wenn sie nicht installiert ist, 1) installieren Sie entw
eder das Microsoft Windows SDK für Windows Server 2008 und .NET Framework 3.5 o
der 2) Microsoft Visual Studio 2008. [D:\alles\Documents_tellize\feed\node_mo
dules\bcrypt\build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files (x86)\nodejs\node_mo
dules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1067
:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\Program Files (x86)\nodejs\node_modules\npm\nod
e_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd D:\alles\Documents_tellize\feed\node_modules\bcrypt
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.2
gyp ERR! not ok

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files (x86)\nodejs\node.exe" "C:\Program Files (
x86)\nodejs\node_modules\npm\bin\npm-cli.js" "install"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! D:\alles\Documents_tellize\feed\npm-debug.log

RHEL6 wont compile no c++11 available

I was wondering if there was any options. I am installing an applicatoin that lists bcrypt as a module and it will not build on RHEL6.0 which I need to keep as this is older hardware.

here is the output of the build
`
npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade

[email protected] install /home/elkadmin/semaphore/node_modules/bcrypt
node-gyp rebuild

make: Entering directory /home/elkadmin/semaphore/node_modules/bcrypt/build' CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o In file included from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan.h:41:3: error: #error This version of node/NAN/v8 requires a C++11 compiler In file included from /home/elkadmin/.node-gyp/4.4.3/include/node/node.h:42, from ../node_modules/nan/nan.h:45, from ../src/bcrypt_node.cc:1: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:336: error: expected unqualified-id before ‘using’ /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In constructor ‘v8::MaybeLocal<T>::MaybeLocal()’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:353: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::IsEmpty() const’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:360: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘bool v8::MaybeLocal<T>::ToLocal(v8::Local<S>*) const’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:364: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘bool v8::WeakCallbackInfo<T>::IsFirstPass() const’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:430: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: At global scope: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:469: error: expected unqualified-id before ‘using’ /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In constructor ‘v8::Global<T>::Global()’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:790: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In constructor ‘v8::Global<T>::Global(v8::Global<T>&&)’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:815: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘v8::Global<T>& v8::Global<T>::operator=(v8::Global<S>&&)’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:827: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: At global scope: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:852: error: expected unqualified-id before ‘using’ /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:1089: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:1095: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘v8::MaybeLocal<v8::Object> v8::Function::NewInstance(v8::Local<v8::Context>) const’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:3205: error: ‘nullptr’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘v8::Local<T> v8::MaybeLocal<T>::ToLocalChecked()’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:7164: error: ‘nullptr’ was not declared in this scope In file included from ../node_modules/nan/nan.h:194, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_maybe_43_inl.h: At global scope: ../node_modules/nan/nan_maybe_43_inl.h:13: error: expected unqualified-id before ‘using’ ../node_modules/nan/nan_maybe_43_inl.h:16: error: expected unqualified-id before ‘using’ ../node_modules/nan/nan_maybe_43_inl.h:19: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:24: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:31: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:36: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:41: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:46: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:51: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:59: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:64: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:69: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:76: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:83: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:91: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:98: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:108: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:114: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:118: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:125: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:130: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:135: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:139: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:145: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:150: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:156: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:162: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:168: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:174: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:180: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:186: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:194: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:201: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:205: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:209: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:213: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:217: error: expected initializer before ‘<’ token ../node_modules/nan/nan_maybe_43_inl.h:223: error: expected initializer before ‘<’ token In file included from ../node_modules/nan/nan.h:199, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_converters.h:14: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type ../node_modules/nan/nan_converters.h:14: error: expected ‘;’ before ‘<’ token ../node_modules/nan/nan_converters.h:16: error: ISO C++ forbids declaration of ‘Maybe’ with no type ../node_modules/nan/nan_converters.h:16: error: expected ‘;’ before ‘<’ token ../node_modules/nan/nan_converters.h:26: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:27: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:28: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:29: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:30: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:31: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:32: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:42: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:43: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:44: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:45: error: ‘return_t’ does not name a type ../node_modules/nan/nan_converters.h:46: error: ‘return_t’ does not name a type In file included from ../node_modules/nan/nan_converters.h:59, from ../node_modules/nan/nan.h:199, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_converters_43_inl.h:18: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Boolean>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:19: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Number>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:20: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::String>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:21: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Object>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:22: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Integer>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:23: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Uint32>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:24: error: ‘return_t’ in class ‘Nan::imp::ToFactory<v8::Int32>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:34: error: ‘return_t’ in class ‘Nan::imp::ToFactory<bool>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:35: error: ‘return_t’ in class ‘Nan::imp::ToFactory<double>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:36: error: ‘return_t’ in class ‘Nan::imp::ToFactory<long int>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:37: error: ‘return_t’ in class ‘Nan::imp::ToFactory<unsigned int>’ does not name a type ../node_modules/nan/nan_converters_43_inl.h:38: error: ‘return_t’ in class ‘Nan::imp::ToFactory<int>’ does not name a type In file included from ../node_modules/nan/nan.h:200, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Integer]’: ../node_modules/nan/nan_new.h:21: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’ ../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Int32]’: ../node_modules/nan/nan_new.h:28: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’ ../node_modules/nan/nan_new.h: In function ‘v8::Local<T> Nan::imp::To(v8::Local<v8::Integer>) [with T = v8::Uint32]’: ../node_modules/nan/nan_new.h:35: error: no matching function for call to ‘To(v8::Local<v8::Integer>&)’ ../node_modules/nan/nan_new.h: At global scope: ../node_modules/nan/nan_new.h:43: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type ../node_modules/nan/nan_new.h:43: error: expected ‘;’ before ‘<’ token ../node_modules/nan/nan_new.h:75: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:141: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:147: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:148: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:160: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:161: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:162: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:163: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:165: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:166: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:182: error: ‘return_t’ does not name a type ../node_modules/nan/nan_new.h:183: error: ‘return_t’ does not name a type In file included from ../node_modules/nan/nan_new.h:189, from ../node_modules/nan/nan.h:200, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_implementation_12_inl.h:56: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::Date>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::Function> Nan::imp::Factory<v8::Function>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’: ../node_modules/nan/nan_implementation_12_inl.h:90: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan_implementation_12_inl.h: In static member function ‘static v8::Local<v8::FunctionTemplate> Nan::imp::Factory<v8::FunctionTemplate>::New(void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>, v8::Local<v8::Signature>)’: ../node_modules/nan/nan_implementation_12_inl.h:118: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan_implementation_12_inl.h: At global scope: ../node_modules/nan/nan_implementation_12_inl.h:197: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:216: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::Script>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:222: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::Script>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:254: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:262: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:268: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:275: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:281: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:286: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:347: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type ../node_modules/nan/nan_implementation_12_inl.h:354: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::UnboundScript>’ does not name a type In file included from ../node_modules/nan/nan.h:200, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_new.h:293: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:299: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:305: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:311: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:317: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:323: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:329: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::String>’ does not name a type ../node_modules/nan/nan_new.h:335: error: ‘return_t’ in class ‘Nan::imp::Factory<v8::RegExp>’ does not name a type In file included from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::Error(const char*)’: ../node_modules/nan/nan.h:659: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::ThrowError(const char*)’: ../node_modules/nan/nan.h:659: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::RangeError(const char*)’: ../node_modules/nan/nan.h:660: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::ThrowRangeError(const char*)’: ../node_modules/nan/nan.h:660: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::ReferenceError(const char*)’: ../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::ThrowReferenceError(const char*)’: ../node_modules/nan/nan.h:661: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::SyntaxError(const char*)’: ../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::ThrowSyntaxError(const char*)’: ../node_modules/nan/nan.h:662: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘v8::Local<v8::Value> Nan::TypeError(const char*)’: ../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::ThrowTypeError(const char*)’: ../node_modules/nan/nan.h:663: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: At global scope: ../node_modules/nan/nan.h:671: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:693: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:709: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:722: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:739: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:745: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:753: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:760: error: expected initializer before ‘<’ token ../node_modules/nan/nan.h:766: error: expected initializer before ‘<’ token /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h: In member function ‘void Nan::Callback::SetFunction(const v8::Local<v8::Function>&)’: /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’ ../node_modules/nan/nan.h:1402: error: in call to ‘Set’ ../node_modules/nan/nan.h: In member function ‘void Nan::AsyncWorker::SaveToPersistent(const char*, const v8::Local<v8::Value>&)’: ../node_modules/nan/nan.h:1522: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In member function ‘v8::Local<v8::Value> Nan::AsyncWorker::GetFromPersistent(const char*) const’: ../node_modules/nan/nan.h:1540: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In member function ‘virtual void Nan::AsyncWorker::HandleErrorCallback()’: ../node_modules/nan/nan.h:1574: error: no matching function for call to ‘New(const char*)’ ../node_modules/nan/nan.h: In function ‘void Nan::SetMethod(const T&, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’: ../node_modules/nan/nan.h:1857: error: there are no arguments to ‘GetFunction’ that depend on a template parameter, so a declaration of ‘GetFunction’ must be available ../node_modules/nan/nan.h:1857: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) ../node_modules/nan/nan.h:1858: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::SetPrototypeMethod(v8::Local<v8::FunctionTemplate>, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’: ../node_modules/nan/nan.h:1870: error: ‘GetFunction’ was not declared in this scope ../node_modules/nan/nan.h:1871: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)’: ../node_modules/nan/nan.h:1896: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan.h: In function ‘bool Nan::SetAccessor(v8::Local<v8::Object>, v8::Local<v8::String>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<void>&), v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute)’: ../node_modules/nan/nan.h:1939: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan.h: In function ‘void Nan::SetNamedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(v8::Local<v8::String>, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’: ../node_modules/nan/nan.h:1987: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan.h: In function ‘void Nan::SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate>, void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, v8::Local<v8::Value>, const Nan::PropertyCallbackInfo<v8::Value>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Integer>&), void (*)(uint32_t, const Nan::PropertyCallbackInfo<v8::Boolean>&), void (*)(const Nan::PropertyCallbackInfo<v8::Array>&), v8::Local<v8::Value>)’: ../node_modules/nan/nan.h:2057: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan.h: In function ‘void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’: ../node_modules/nan/nan.h:2112: error: ‘NewInstance’ was not declared in this scope ../node_modules/nan/nan.h: In function ‘void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate>, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&), v8::Local<v8::Value>)’: ../node_modules/nan/nan.h:2134: error: ‘NewInstance’ was not declared in this scope In file included from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan.h: In function ‘void Nan::Export(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE, const char*, void (*)(const Nan::FunctionCallbackInfo<v8::Value>&))’: ../node_modules/nan/nan.h:2161: error: no matching function for call to ‘New(const char*&)’ ../node_modules/nan/nan.h:2162: error: ‘GetFunction’ was not declared in this scope /home/elkadmin/.node-gyp/4.4.3/include/node/v8.h:3021: error: argument dependent lookup finds ‘class v8::Set’ ../node_modules/nan/nan.h:2162: error: in call to ‘Set’ ../node_modules/nan/nan.h: In constructor ‘Nan::Tap::Tap(v8::Local<v8::Value>)’: ../node_modules/nan/nan.h:2169: error: no matching function for call to ‘To(v8::Local<v8::Value>&)’ ../node_modules/nan/nan.h: In member function ‘void Nan::Tap::ok(bool, const char*)’: ../node_modules/nan/nan.h:2182: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: In member function ‘void Nan::Tap::pass(const char*)’: ../node_modules/nan/nan.h:2188: error: ‘class v8::Local<v8::Boolean>’ has no member named ‘ToLocalChecked’ ../node_modules/nan/nan.h: At global scope: ../node_modules/nan/nan.h:2212: error: ISO C++ forbids declaration of ‘MaybeLocal’ with no type ../node_modules/nan/nan.h:2212: error: expected ‘;’ before ‘<’ token ../node_modules/nan/nan.h:2215: error: expected ‘;’ before ‘}’ token ../node_modules/nan/nan.h:2217: error: ‘MaybeLocal’ was not declared in this scope ../node_modules/nan/nan.h:2217: error: template argument 1 is invalid ../node_modules/nan/nan.h:2217: error: expected unqualified-id before ‘>’ token ../node_modules/nan/nan.h:2226: error: expected constructor, destructor, or type conversion before ‘<’ token ../src/bcrypt_node.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE<unnamed>::GenerateSalt(const Nan::FunctionCallbackInfo<v8::Value>&)’: ../src/bcrypt_node.cc:108: error: no matching function for call to ‘To(v8::Local<v8::Value>)’ ../src/bcrypt_node.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE<unnamed>::GenerateSaltSync(const Nan::FunctionCallbackInfo<v8::Value>&)’: ../src/bcrypt_node.cc:131: error: no matching function for call to ‘To(v8::Local<v8::Value>)’ make: *** [Release/obj.target/bcrypt_lib/src/bcrypt_node.o] Error 1 make: Leaving directory/home/elkadmin/semaphore/node_modules/bcrypt/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/home/elkadmin/node-v4.4.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 2.6.32-573.el6.x86_64
gyp ERR! command "/home/elkadmin/node-v4.4.3-linux-x64/bin/node" "/home/elkadmin/node-v4.4.3-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/elkadmin/semaphore/node_modules/bcrypt
gyp ERR! node -v v4.4.3
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok
npm ERR! Linux 2.6.32-573.el6.x86_64
npm ERR! argv "/home/elkadmin/node-v4.4.3-linux-x64/bin/node" "/home/elkadmin/node/bin/npm" "install"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs bcrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/elkadmin/semaphore/npm-debug.log
`

Example not working

The example in README doesn't work and throws an error

var hash = bcrypt.hashSync("bacon");
Error: data and salt arguments required

NPM homepage github link is a 404

Currently:

screen shot 2015-01-16 at 5 55 02 pm

The Github link leads to a 404. Manually adding "-nodejs" to the URL let me find the repo, but the link is currently borked. Your package.json has the right link, so you might just need to update with NPM.

Standardized license

Hello, can you please use standardized license for project and also add it to package.json

bcrypt compare always return fall

Hello,
I'm implementing an user auth with Bcrypt.
I'm facing an issue when comparing the given password with the one store in my DB i always have a false message.
here is my compare method :

bcrypt.compare(param.motdepasse , client.motdepasse, function(err, pass) {
if(err) res.json(200,{Message :'Error'});
if(pass == true){
client.isAuthenticate = 'true';
res.json(client);
}else{
res.json(200,{Message :'Mot de passe érronée !'});
}

  });

Please any idea? thk!

Which Cypto?

Wonderful thanks! I too have had trouble installing all of the Windows dependencies. Concerning dependencies which “crypto” does bCrypt.js depend on? Sorry if this should be obvious…
Would it be possible to include this crypto as part of the npm package?
Thanks!

Documentation is wrong for hash

hash has an undocumented progress parameter in position 3, not the callback function which is argument 4 - I suggest to either dynamically detect when it is not passed in (ie. progress is non-null, but callback is null - assume progress is callback) or update the documentation to state this.

Please mark the npm package / this project as deprecated

In the repo you have stated that "This project is not actively maintained" Can you please push a deprecation message to npm's repo. I suspect you would need to run the following:

npm deprecate bcrypt-nodejs "bcrypt-nodejs is no longer actively maintained. Please use bcrypt or bcryptjs. See https://github.com/kelektiv/node.bcrypt.js/wiki/bcrypt-vs-brypt.js to learn more about these two options"

Ref: https://docs.npmjs.com/cli/deprecate

Maybe a CompareSync Bug

I encounter an issue when using CompareSync in model

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');

// create a schema
var userSchema = new Schema({
  username: { type: String, required: true, unique: true },
  password: {type: String, required:true}
});

userSchema.methods.generateHash = function(password) {
  return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};

// checking if password is valid
userSchema.methods.validPassword = function(password) {
  console.log("Normal call 7 " + password + "\t" + this.password); //todo debug line
  var result = bcrypt.compareSync(password, this.password);
  console.log("Normal 8" + result);
  return bcrypt.compareSync(password, this.password);
};

var Users = mongoose.model('Users', userSchema);
module.exports = Users;

The result is as follows

Normal call 7 password1234      password1234

events.js:74
        throw TypeError('Uncaught, unspecified "error" event.');
              ^
TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at Function.EventEmitter.emit (events.js:74:15)
    at Query.<anonymous> (<project dir>/node_modules/mongoose/lib/model.js:3326:13)
    at <project dir>/node_modules/mongoose/node_modules/kareem/index.js:259:21
    at <project dir>/node_modules/mongoose/node_modules/kareem/index.js:127:16
    at process._tickCallback (node.js:415:13)

As you can see, the program is normal before calling compareSync, and the Strings to compare are quite reasonable, and it throws an exception

Latest version is not published

I am not sure if this is intentional, but the npm module has not been published since version 0.3.0 (latest version is 0.1.0).

In other words, the most recent patches are not live. Also, it looks like you changed the name of this repository at some point, from bcryptJS to bcrypt-nodejs. npm still points to the old repository link which results in a 404 now 😢 (the clone url results in a redirect, so the installation still works.)

"Octal literal in strict mode" error in Webpack

Webpack shows me an error at ./node_modules/bcrypt-nodejs/bCrypt.js (293:40), anyone know how to fix this?

ERROR in ./node_modules/bcrypt-nodejs/bCrypt.js
Module parse failed: Octal literal in strict mode (293:40)
You may need an appropriate loader to handle this file type.
|       rounds = r1 + r2;
|       real_salt = salt.substring(off + 3, off + 25);
|       password = password + (minor >= 'a' ? "\000" : "");
|
|       var buf = new Buffer(password);

Add npm install bcrypt-nodejs to readme?

The current README does not make it clear how to install this module.
Can I add:

npm install bcrypt-nodejs

To clarify this for people who arrive at the GitHub repo rather than finding through npm?

Salt in final hash result

Hi,

Could you please elaborate in the docs regarding the following statement please:

Though you can use your custom salt and there is no need for salts to be persisted as it will always be included in the final hash result and can be retrieved.

Thanks, we'll all benefit.

Hash collisions for UTF-8 passwords

Before I start, thanks for a very good module. I like the idea of using a pure javascript code in my node application instead of having to compile native code. I don't know however if I shall use your module in my project due to the following issue.

The following code shows a hash collision between two different password ( one each a different chinese character ).

/*jslint node: true, indent: 4, stupid: true */
var bcrypt = require('bcrypt-nodejs'),
    pw1 = '\u6e2f',  // http://www.fileformat.info/info/unicode/char/6e2f/index.htm
    pw2 = '\u6f2f',  // http://www.fileformat.info/info/unicode/char/6f2f/index.htm
    salt = '$2a$05$0000000000000000000000',
    hash1 = bcrypt.hashSync(pw1, salt),
    hash2 = bcrypt.hashSync(pw2, salt);

console.log(hash1);
console.log(hash2);
if (hash1 === hash2) {
    console.log('Hash collision !!!!');
} else {
    console.log('Hashes are different, as expected.');
}

This is most probably related to the following loop in hashpw():

for (var r = 0; r < password.length; r++) {
    passwordb.push(getByte(password.charAt(r)));
}

This look goes through the password string using only 1 byte from each characters. This means that multi-byte UTF-8 characters will result in potentially the same hash if the last byte of the corresponding characters are similar.

I already opened an issue at http://code.google.com/p/javascript-bcrypt/issues/detail?id=8 since this is the basis for your implementation. I compared the results from your package to https://github.com/ncb000gt/node.bcrypt.js/ which is an implementation around the FreeBSD native C++ code and your module gives different results.

The C++ implementation uses a string as an array of UTF-8 bytes. For example, the UTF-8 of Chinese character 0x6e2F used above is three bytes: [0xE6, 0xB8, 0xAF]. If I feed that array to your algorithm, I get the same exact result as the C++ implementation.

The next step to me is to find a way to convert a UTF-8 string into the C++ equivalent array of UTF-8 bytes. I want character 0x1234 to become [0xE1 0x88 0xB4], not [0x12, 0x34]. I'll investigate that next but I wanted to let you know immediately about the problem in your module.

Regards.

bcrypt compare returns false all the time

Hi there,

I'm implementing user authentication using bcrypt. Bcrypt compare is returning false despite the password being correct. Interestingly, bcrypt compare works on a local db but not on a hosted remote db. (not a password string length issue) Any idea what might be the problem?

UserSchema.methods.validPassword = function (password, next) {
    var user = this;

    bcrypt.compare(password, user.password, function (err, isMatch) {
        if (err) {
            console.log('PW COMPARE ERR: Validation process failed')
            next(err)
        };

        next(null, isMatch)
    })
};

Use strict mode not working

Hello,

This library is not compatible with "use strict" mode. If you launch a project with:

node --use_strict --harmony myProject.js

Then, the following errors occurs:

./node_modules/bcrypt-nodejs/bCrypt.js:519
    password = password + (minor >= 'a' ? "\000" : "");
                                            ^^
SyntaxError: Octal literals are not allowed in strict mode.

Would it be possible to fix this?

Thanks

GenSalt taking longer on fewer rounds

I've tested from 1 to 10 rounds for genSalt, and on my hardware genSalt(3, cb) will take longer than genSalt(4, cb) (125ms vs 40ms). Round values between 4 and 8 yield are faster than genSalt(3, cb), any ideas why?

Error: global leak detected: lr

Hi,

At some place in your code you are missing the "var" statement and thereby declare a global variable. I get the following error in a mocha test case: Error: global leak detected: lr

Potentially in the function crypt_raw.

Cheers

New release for the global leak fix

Hey - since #8 was merged, I don't believe there has been a new npm release, so the latest (0.0.3) still has the global leak. Would you be able to cut a new release for that fix? Thanks.

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.