const crypto = require('crypto');
const util = require('util');
const cryptoPbkdf2 = util.promisify(crypto.pbkdf2);
let hashLength = 16;
let iterations = 10;
async function createSaltHash(email) {
let salt = crypto.randomBytes(hashLength).toString('base64');
let hash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
return { salt, hash }
};
async function checkSaltHash(email, salt, hash) {
if (!email || !hash || !salt) return false;
let userHash = (await cryptoPbkdf2(email, salt, iterations, hashLength, 'sha512')).toString();
let check = userHash == hash;
return check;
};