2018-05-29 00:01:01 +03:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
|
2018-02-15 23:13:04 +03:00
|
|
|
module.exports.hash = function hash(plainPassword) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const bcryptGenSalt = Promise.promisify(bcrypt.genSalt);
|
|
|
|
const bcryptHash = Promise.promisify(bcrypt.hash);
|
2018-02-15 23:13:04 +03:00
|
|
|
|
|
|
|
return bcryptGenSalt().then(function (salt) {
|
|
|
|
return bcryptHash(plainPassword, salt);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const bcryptCompare = Promise.promisify(bcrypt.compare);
|
2018-02-15 23:13:04 +03:00
|
|
|
|
|
|
|
return bcryptCompare(plainPassword, hashedPassword);
|
|
|
|
};
|