Added lib.security.password lib

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
This commit is contained in:
kirrg001 2018-02-15 21:13:04 +01:00
parent 72911862e7
commit 5d1a4418bd
2 changed files with 22 additions and 0 deletions

View File

@ -15,5 +15,9 @@ module.exports = {
get identifier() { get identifier() {
return require('./identifier'); return require('./identifier');
},
get password() {
return require('./password');
} }
}; };

View File

@ -0,0 +1,18 @@
'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);
};