Created
March 30, 2016 02:29
-
-
Save davidbarsky/1106b41c42dfed9eba3577c2ba13e7e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Promise = require('bluebird'); | |
const crypto = Promise.promisifyAll(require('crypto')); | |
const argon = Promise.promisifyAll(require('argon2-ffi').argon2i); | |
const securePassword = (rawPassword) => { | |
crypto.randomBytes(16, (err, salt) => { | |
if (err) throw err; | |
argon.hash(rawPassword, salt, (err, hash) => { | |
}) | |
}) | |
}; | |
module.exports.securePassword = securePassword; |
Closer to what you already have (with bluebird
):
const Promise = require('bluebird');
const crypto = Promise.promisifyAll(require('crypto'));
const argon = Promise.promisifyAll(require('argon2-ffi').argon2i);
function securePassword(rawPassword) {
return crypto.randomBytes(16).then(salt => {
return argon.hash(rawPassword, salt);
}).then(hash => {
// do something with the hash
return hash;
});
// add catch if needed
}
module.exports.securePassword = securePassword;
(although I'm a little confused why you are using a different random salt each time, unless your gonna store the salt too)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With Q