Code maintenance, small refactors (#3811)

* Removes promise wrapping in AccountLockoutPolicy

* Use bcrypt promises as globally available
This commit is contained in:
Florent Vilmart
2017-05-14 19:37:42 -04:00
committed by GitHub
parent ab5b759e26
commit d71683a7e2
2 changed files with 34 additions and 95 deletions

View File

@@ -8,33 +8,17 @@ try {
// Returns a promise for a hashed password string.
function hash(password) {
return new Promise(function(fulfill, reject) {
bcrypt.hash(password, 10, function(err, hashedPassword) {
if (err) {
reject(err);
} else {
fulfill(hashedPassword);
}
});
});
return bcrypt.hash(password, 10);
}
// Returns a promise for whether this password compares to equal this
// hashed password.
function compare(password, hashedPassword) {
return new Promise(function(fulfill, reject) {
// Cannot bcrypt compare when one is undefined
if (!password || !hashedPassword) {
return fulfill(false);
}
bcrypt.compare(password, hashedPassword, function(err, success) {
if (err) {
reject(err);
} else {
fulfill(success);
}
});
});
// Cannot bcrypt compare when one is undefined
if (!password || !hashedPassword) {
return Promise.resolve(false);
}
return bcrypt.compare(password, hashedPassword);
}
module.exports = {