RyanMarcus icon

Untitled

RyanMarcus | PRO | 03/30/16 02:32:41 AM UTC | 0 ⭐ | 295 👁️ | Never ⏰ | []
JavaScript |

580 B

|

None

|

0 👍

/

0 👎

const Promise = require('bluebird');
const crypto = Promise.promisifyAll(require('crypto'));
const argon = Promise.promisifyAll(require('argon2-ffi').argon2i);
const Q = require('q');
 
const securePassword = (rawPassword) => {
    let toR = Q.defer();
    
    crypto.randomBytes(16, (err, salt) => {
    if (err) {
        toR.reject(err);
        return;
    }
 
    argon.hash(rawPassword, salt, (err, hash) => {
        if (err) {
        toR.reject(err);
        return;
        }
 
        toR.resolve(hash);
    });
    });
 
    return toR.promise;
 
    
};
module.exports.securePassword = securePassword;

Comments