5d1a4418bd
no issue - move password hashing and password comparison to lib/security/password - added two unit test - FYI: password hashing takes ~100ms - we could probably mock password hashing in certain cases when unit testing
19 lines
566 B
JavaScript
19 lines
566 B
JavaScript
'use strict';
|
|
|
|
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);
|
|
};
|