Ghost/ghost/security/lib/password.js
Daniel Lockyer ae336f19cd
Protected against missing NODE_ENV variable
- in the event NODE_ENV isn't set, this would throw an error because
  `startsWith` is a function call on `undefined`
2022-08-18 08:34:53 +02:00

17 lines
431 B
JavaScript

const bcrypt = require('bcryptjs');
let HASH_ROUNDS = 10;
if (process.env.NODE_ENV?.startsWith('testing')) {
HASH_ROUNDS = 1;
}
module.exports.hash = async function hash(plainPassword) {
const salt = await bcrypt.genSalt(HASH_ROUNDS);
return bcrypt.hash(plainPassword, salt);
};
module.exports.compare = function compare(plainPassword, hashedPassword) {
return bcrypt.compare(plainPassword, hashedPassword);
};