Skip to content

Commit 3a08ec9

Browse files
flovilmartdrew-gross
authored andcommitted
Adds bcrypt native binding for better login performance (#2549)
* Adds bcrypt native binding for better login performance * Swaps bcrypt-nodejs for bcryptjs as compatible with bcrypt native * Fixes package versions
1 parent 9429659 commit 3a08ec9

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "BSD-3-Clause",
2020
"dependencies": {
2121
"babel-polyfill": "6.13.0",
22-
"bcrypt-nodejs": "0.0.3",
22+
"bcryptjs": "2.3.0",
2323
"body-parser": "1.15.2",
2424
"commander": "2.9.0",
2525
"deepcopy": "0.6.3",
@@ -53,14 +53,15 @@
5353
"babel-preset-es2015": "6.13.2",
5454
"babel-preset-stage-0": "6.5.0",
5555
"babel-register": "6.11.6",
56+
"bcrypt-nodejs": "0.0.3",
5657
"cross-env": "2.0.0",
5758
"deep-diff": "0.3.4",
5859
"gaze": "1.1.1",
5960
"istanbul": "1.0.0-alpha.1",
6061
"jasmine": "2.4.1",
6162
"mongodb-runner": "3.3.2",
6263
"nodemon": "1.10.0",
63-
"request-promise": "^4.1.1"
64+
"request-promise": "4.1.1"
6465
},
6566
"scripts": {
6667
"dev": "npm run build && node bin/dev",
@@ -77,5 +78,8 @@
7778
},
7879
"bin": {
7980
"parse-server": "./bin/parse-server"
81+
},
82+
"optionalDependencies": {
83+
"bcrypt": "0.8.7"
8084
}
8185
}

spec/Auth.spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ describe('Auth', () => {
7777
auth.getUserRoles()
7878
.then((roles) => expect(roles).toEqual([]))
7979
.then(() => done());
80-
})
80+
});
81+
82+
it('should properly handle bcrypt upgrade', (done) => {
83+
var bcryptOriginal = require('bcrypt-nodejs');
84+
var bcryptNew = require('bcryptjs');
85+
bcryptOriginal.hash('my1Long:password', null, null, function(err, res) {
86+
bcryptNew.compare('my1Long:password', res, function(err, res) {
87+
expect(res).toBeTruthy();
88+
done();
89+
})
90+
});
91+
});
8192

8293
});
8394
});

src/password.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// Tools for encrypting and decrypting passwords.
22
// Basically promise-friendly wrappers for bcrypt.
3-
var bcrypt = require('bcrypt-nodejs');
3+
var bcrypt = require('bcryptjs');
4+
5+
try {
6+
bcrypt = require('bcrypt');
7+
} catch(e) {}
48

59
// Returns a promise for a hashed password string.
610
function hash(password) {
711
return new Promise(function(fulfill, reject) {
8-
bcrypt.hash(password, null, null, function(err, hashedPassword) {
12+
bcrypt.hash(password, 10, function(err, hashedPassword) {
913
if (err) {
1014
reject(err);
1115
} else {

0 commit comments

Comments
 (0)