Skip to content

Commit

Permalink
Replace nodejs-bcrypt with bcryptjs
Browse files Browse the repository at this point in the history
halfdan committed Oct 23, 2013
1 parent ce2c7b5 commit 1af1772
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions core/server/models/user.js
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",

0 comments on commit 1af1772

Please sign in to comment.