I am currently developing a login for my website, (using node.js and MySQL) and would like some feedback on the password hashing code.
const crypto = require('crypto');
function RandomSaltString(length) {
return crypto.randomBytes(Math.ceil(length/2))//I have absolutely no idea what this is
.toString('hex') //And this
.slice(0,length); //Well I think know this thought
};
function Hash(password, salt) {
var hash = crypto.createHmac('sha512', salt);
hash.update(password);
return hash.digest('hex');
};
function preparePasswordForStorage(password) {
var salt = randomString(20);
const hashedPassword = hashFunc(password, salt);
//Will encrypt the hashed password and salt here once I figure it out.
return {
hashedPass: hashedPassword,
salt: salt //Will be stored in db directly after this.
}
};