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'),
|
||||
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 };
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue