mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 03:44:29 +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');
|
||||
|
||||
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);
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user