mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Replace nodejs-bcrypt with bcryptjs
* https://github.com/shaneGirish/bcrypt-nodejs * https://github.com/dcodeIO/bcrypt.js
This commit is contained in:
parent
ce2c7b5341
commit
1af17725fc
2 changed files with 12 additions and 6 deletions
|
@ -5,7 +5,7 @@ var User,
|
||||||
when = require('when'),
|
when = require('when'),
|
||||||
errors = require('../errorHandling'),
|
errors = require('../errorHandling'),
|
||||||
nodefn = require('when/node/function'),
|
nodefn = require('when/node/function'),
|
||||||
bcrypt = require('bcrypt-nodejs'),
|
bcrypt = require('bcryptjs'),
|
||||||
Posts = require('./post').Posts,
|
Posts = require('./post').Posts,
|
||||||
ghostBookshelf = require('./base'),
|
ghostBookshelf = require('./base'),
|
||||||
Role = require('./role').Role,
|
Role = require('./role').Role,
|
||||||
|
@ -92,7 +92,6 @@ User = ghostBookshelf.Model.extend({
|
||||||
var self = this,
|
var self = this,
|
||||||
// Clone the _user so we don't expose the hashed password unnecessarily
|
// Clone the _user so we don't expose the hashed password unnecessarily
|
||||||
userData = _.extend({}, _user);
|
userData = _.extend({}, _user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This only allows one user to be added to the database, otherwise fails.
|
* This only allows one user to be added to the database, otherwise fails.
|
||||||
* @param {object} user
|
* @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!'));
|
return when.reject(new Error('A user is already registered. Only one user for now!'));
|
||||||
}
|
}
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
|
// Generate a new salt
|
||||||
|
return nodefn.call(bcrypt.genSalt);
|
||||||
|
}).then(function (salt) {
|
||||||
// Hash the provided password with bcrypt
|
// 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) {
|
}).then(function (hash) {
|
||||||
// Assign the hashed password
|
// Assign the hashed password
|
||||||
userData.password = hash;
|
userData.password = hash;
|
||||||
|
@ -186,7 +188,9 @@ User = ghostBookshelf.Model.extend({
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
return when.reject(new Error('Your password is incorrect'));
|
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) {
|
}).then(function (hash) {
|
||||||
user.save({password: hash});
|
user.save({password: hash});
|
||||||
|
|
||||||
|
@ -200,7 +204,9 @@ User = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
return this.forge({email: email}).fetch({require: true}).then(function (_user) {
|
return this.forge({email: email}).fetch({require: true}).then(function (_user) {
|
||||||
user = _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) {
|
}).then(function (hash) {
|
||||||
user.save({password: hash});
|
user.save({password: hash});
|
||||||
return { user: user, newPassword: newPassword };
|
return { user: user, newPassword: newPassword };
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
"bookshelf": "0.5.7",
|
"bookshelf": "0.5.7",
|
||||||
"knex": "0.4.11",
|
"knex": "0.4.11",
|
||||||
"when": "2.2.1",
|
"when": "2.2.1",
|
||||||
"bcrypt-nodejs": "0.0.3",
|
"bcryptjs": "0.7.10",
|
||||||
"node-uuid": "1.4.0",
|
"node-uuid": "1.4.0",
|
||||||
"colors": "0.6.1",
|
"colors": "0.6.1",
|
||||||
"semver": "2.1.0",
|
"semver": "2.1.0",
|
||||||
|
|
Loading…
Reference in a new issue