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) {
|
|
|
|
const bcrypt = require('bcryptjs'),
|
|
|
|
bcryptGenSalt = Promise.promisify(bcrypt.genSalt),
|
|
|
|
bcryptHash = Promise.promisify(bcrypt.hash);
|
|
|
|
|
|
|
|
return bcryptGenSalt().then(function (salt) {
|
|
|
|
return bcryptHash(plainPassword, salt);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
|
|
|
const bcrypt = require('bcryptjs'),
|
|
|
|
bcryptCompare = Promise.promisify(bcrypt.compare);
|
|
|
|
|
|
|
|
return bcryptCompare(plainPassword, hashedPassword);
|
|
|
|
};
|