Skip to content

Adds bcrypt native binding for better login performance #2549

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

Merged
merged 3 commits into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "BSD-3-Clause",
"dependencies": {
"babel-polyfill": "6.13.0",
"bcrypt-nodejs": "0.0.3",
"bcryptjs": "2.3.0",
"body-parser": "1.15.2",
"commander": "2.9.0",
"deepcopy": "0.6.3",
Expand Down Expand Up @@ -53,14 +53,15 @@
"babel-preset-es2015": "6.13.2",
"babel-preset-stage-0": "6.5.0",
"babel-register": "6.11.6",
"bcrypt-nodejs": "0.0.3",
"cross-env": "2.0.0",
"deep-diff": "0.3.4",
"gaze": "1.1.1",
"istanbul": "1.0.0-alpha.1",
"jasmine": "2.4.1",
"mongodb-runner": "3.3.2",
"nodemon": "1.10.0",
"request-promise": "^4.1.1"
"request-promise": "4.1.1"
},
"scripts": {
"dev": "npm run build && node bin/dev",
Expand All @@ -77,5 +78,8 @@
},
"bin": {
"parse-server": "./bin/parse-server"
},
"optionalDependencies": {
"bcrypt": "0.8.7"
}
}
13 changes: 12 additions & 1 deletion spec/Auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ describe('Auth', () => {
auth.getUserRoles()
.then((roles) => expect(roles).toEqual([]))
.then(() => done());
})
});

it('should properly handle bcrypt upgrade', (done) => {
var bcryptOriginal = require('bcrypt-nodejs');
var bcryptNew = require('bcryptjs');
bcryptOriginal.hash('my1Long:password', null, null, function(err, res) {
bcryptNew.compare('my1Long:password', res, function(err, res) {
expect(res).toBeTruthy();
done();
})
});
});

});
});
8 changes: 6 additions & 2 deletions src/password.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Tools for encrypting and decrypting passwords.
// Basically promise-friendly wrappers for bcrypt.
var bcrypt = require('bcrypt-nodejs');
var bcrypt = require('bcryptjs');

try {
bcrypt = require('bcrypt');
} catch(e) {}

// Returns a promise for a hashed password string.
function hash(password) {
return new Promise(function(fulfill, reject) {
bcrypt.hash(password, null, null, function(err, hashedPassword) {
bcrypt.hash(password, 10, function(err, hashedPassword) {
if (err) {
reject(err);
} else {
Expand Down