- This commit replaces bcrypt with bcrypt-node, which has the same functionality as bcrypy - except that it is a pure Node implementation. This change is required to run parse-server on Windows (one can get bcrypt to compile on Windows, but it requires a few Gigabytes of dependencies).
36 lines
852 B
JavaScript
36 lines
852 B
JavaScript
// Tools for encrypting and decrypting passwords.
|
|
// Basically promise-friendly wrappers for bcrypt.
|
|
var bcrypt = require('bcrypt-nodejs');
|
|
|
|
// Returns a promise for a hashed password string.
|
|
function hash(password) {
|
|
return new Promise(function(fulfill, reject) {
|
|
bcrypt.hash(password, 8, function(err, hashedPassword) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
fulfill(hashedPassword);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
// Returns a promise for whether this password compares to equal this
|
|
// hashed password.
|
|
function compare(password, hashedPassword) {
|
|
return new Promise(function(fulfill, reject) {
|
|
bcrypt.compare(password, hashedPassword, function(err, success) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
fulfill(success);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
hash: hash,
|
|
compare: compare
|
|
};
|