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:
Vikas Potluri 2022-08-01 08:21:19 -07:00 committed by GitHub
parent a5084c7ee6
commit 59f4570ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 21 deletions

View File

@ -1,18 +1,9 @@
const Promise = require('bluebird');
module.exports.hash = function hash(plainPassword) {
const bcrypt = require('bcryptjs');
const bcryptGenSalt = Promise.promisify(bcrypt.genSalt);
const bcryptHash = Promise.promisify(bcrypt.hash);
return bcryptGenSalt().then(function (salt) {
return bcryptHash(plainPassword, salt);
});
const bcrypt = require('bcryptjs');
module.exports.hash = async function hash(plainPassword) {
const salt = await bcrypt.genSalt();
return bcrypt.hash(plainPassword, salt);
};
module.exports.compare = function compare(plainPassword, hashedPassword) {
const bcrypt = require('bcryptjs');
const bcryptCompare = Promise.promisify(bcrypt.compare);
return bcryptCompare(plainPassword, hashedPassword);
return bcrypt.compare(plainPassword, hashedPassword);
};

View File

@ -1,10 +1,8 @@
const _ = require('lodash');
const slugify = require('@tryghost/string').slugify;
module.exports.safe = function safe(string, options) {
options = options || {};
module.exports.safe = function safe(string, options = {}) {
let opts = {requiredChangesOnly: true};
if (!_.has(options, 'importing') || !options.importing) {
if (!('importing' in options) || !options.importing) {
opts.requiredChangesOnly = false;
}
return slugify(string, opts);

View File

@ -22,8 +22,6 @@
},
"dependencies": {
"@tryghost/string": "0.1.26",
"bcryptjs": "2.4.3",
"bluebird": "3.7.2",
"lodash": "4.17.21"
"bcryptjs": "2.4.3"
}
}