@speakr/speakr-module-services
Version:
SPEAKR Shared Service Module
32 lines (24 loc) • 674 B
JavaScript
;
const bcrypt = require('bcryptjs');
const invalidPassword = {
code: 400,
section: '/auth/',
message: 'the username or password you entered does not exist'
};
module.exports = {
password
};
function password(options) {
// Create the promise to contain the resolve or reject
return new Promise((resolve, reject) => {
// Compare passwords
bcrypt.compare(options.params.password, options.users.encrypted_password, (err, matches) => {
// If the passwords match resolve
if (matches) {
return resolve(options);
}
// If the passwords do not match reject
return reject(invalidPassword);
});
})
}