mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
refactored security.password to use native bcrypt promises (#15126)
refs: https://github.com/TryGhost/Ghost/issues/14882 * refactored security.password to use native bcrypt promises * refactored security.string to use more modern es features
This commit is contained in:
parent
a5084c7ee6
commit
59f4570ee7
@ -1,18 +1,9 @@
|
|||||||
const Promise = require('bluebird');
|
const bcrypt = require('bcryptjs');
|
||||||
|
module.exports.hash = async function hash(plainPassword) {
|
||||||
module.exports.hash = function hash(plainPassword) {
|
const salt = await bcrypt.genSalt();
|
||||||
const bcrypt = require('bcryptjs');
|
return bcrypt.hash(plainPassword, salt);
|
||||||
const bcryptGenSalt = Promise.promisify(bcrypt.genSalt);
|
|
||||||
const bcryptHash = Promise.promisify(bcrypt.hash);
|
|
||||||
|
|
||||||
return bcryptGenSalt().then(function (salt) {
|
|
||||||
return bcryptHash(plainPassword, salt);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
||||||
const bcrypt = require('bcryptjs');
|
return bcrypt.compare(plainPassword, hashedPassword);
|
||||||
const bcryptCompare = Promise.promisify(bcrypt.compare);
|
|
||||||
|
|
||||||
return bcryptCompare(plainPassword, hashedPassword);
|
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
const _ = require('lodash');
|
|
||||||
const slugify = require('@tryghost/string').slugify;
|
const slugify = require('@tryghost/string').slugify;
|
||||||
|
|
||||||
module.exports.safe = function safe(string, options) {
|
module.exports.safe = function safe(string, options = {}) {
|
||||||
options = options || {};
|
|
||||||
let opts = {requiredChangesOnly: true};
|
let opts = {requiredChangesOnly: true};
|
||||||
if (!_.has(options, 'importing') || !options.importing) {
|
if (!('importing' in options) || !options.importing) {
|
||||||
opts.requiredChangesOnly = false;
|
opts.requiredChangesOnly = false;
|
||||||
}
|
}
|
||||||
return slugify(string, opts);
|
return slugify(string, opts);
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tryghost/string": "0.1.26",
|
"@tryghost/string": "0.1.26",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3"
|
||||||
"bluebird": "3.7.2",
|
|
||||||
"lodash": "4.17.21"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user