Skip to content

Instantly share code, notes, and snippets.

@davidbarsky
Created March 30, 2016 02:29
Show Gist options
  • Save davidbarsky/1106b41c42dfed9eba3577c2ba13e7e0 to your computer and use it in GitHub Desktop.
Save davidbarsky/1106b41c42dfed9eba3577c2ba13e7e0 to your computer and use it in GitHub Desktop.
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;
@RyanMarcus
Copy link

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