2022-08-01 18:21:19 +03:00
|
|
|
const bcrypt = require('bcryptjs');
|
2022-08-15 13:09:42 +03:00
|
|
|
|
|
|
|
let HASH_ROUNDS = 10;
|
|
|
|
|
2022-08-18 09:33:11 +03:00
|
|
|
if (process.env.NODE_ENV?.startsWith('testing')) {
|
2022-08-15 13:09:42 +03:00
|
|
|
HASH_ROUNDS = 1;
|
|
|
|
}
|
|
|
|
|
2022-08-01 18:21:19 +03:00
|
|
|
module.exports.hash = async function hash(plainPassword) {
|
2022-08-15 13:09:42 +03:00
|
|
|
const salt = await bcrypt.genSalt(HASH_ROUNDS);
|
2022-08-01 18:21:19 +03:00
|
|
|
return bcrypt.hash(plainPassword, salt);
|
2018-02-15 23:13:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
2022-08-01 18:21:19 +03:00
|
|
|
return bcrypt.compare(plainPassword, hashedPassword);
|
2018-02-15 23:13:04 +03:00
|
|
|
};
|