diff --git a/core/server/models/user.js b/core/server/models/user.js index 01097b02f9..cb5862cb4d 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -5,7 +5,7 @@ var User, when = require('when'), errors = require('../errorHandling'), nodefn = require('when/node/function'), - bcrypt = require('bcrypt-nodejs'), + bcrypt = require('bcryptjs'), Posts = require('./post').Posts, ghostBookshelf = require('./base'), Role = require('./role').Role, @@ -92,7 +92,6 @@ User = ghostBookshelf.Model.extend({ var self = this, // Clone the _user so we don't expose the hashed password unnecessarily userData = _.extend({}, _user); - /** * This only allows one user to be added to the database, otherwise fails. * @param {object} user @@ -106,8 +105,11 @@ User = ghostBookshelf.Model.extend({ return when.reject(new Error('A user is already registered. Only one user for now!')); } }).then(function () { + // Generate a new salt + return nodefn.call(bcrypt.genSalt); + }).then(function (salt) { // Hash the provided password with bcrypt - return nodefn.call(bcrypt.hash, _user.password, null, null); + return nodefn.call(bcrypt.hash, _user.password, salt); }).then(function (hash) { // Assign the hashed password userData.password = hash; @@ -186,7 +188,9 @@ User = ghostBookshelf.Model.extend({ if (!matched) { return when.reject(new Error('Your password is incorrect')); } - return nodefn.call(bcrypt.hash, newPassword, null, null); + return nodefn.call(bcrypt.genSalt); + }).then(function (salt) { + return nodefn.call(bcrypt.hash, newPassword, salt); }).then(function (hash) { user.save({password: hash}); @@ -200,7 +204,9 @@ User = ghostBookshelf.Model.extend({ return this.forge({email: email}).fetch({require: true}).then(function (_user) { user = _user; - return nodefn.call(bcrypt.hash, newPassword, null, null); + return nodefn.call(bcrypt.genSalt); + }).then(function (salt) { + return nodefn.call(bcrypt.hash, newPassword, salt); }).then(function (hash) { user.save({password: hash}); return { user: user, newPassword: newPassword }; diff --git a/package.json b/package.json index bd885ade2e..d3e16a9380 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "bookshelf": "0.5.7", "knex": "0.4.11", "when": "2.2.1", - "bcrypt-nodejs": "0.0.3", + "bcryptjs": "0.7.10", "node-uuid": "1.4.0", "colors": "0.6.1", "semver": "2.1.0",