Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash the salt? #30

Open
hayr-hotoca opened this issue Aug 2, 2021 · 0 comments
Open

Hash the salt? #30

hayr-hotoca opened this issue Aug 2, 2021 · 0 comments

Comments

@hayr-hotoca
Copy link

hayr-hotoca commented Aug 2, 2021

Thanks for your works on this!

I want to leave up the password and salt(could be username, email, phone, ...) for the user and save the key and the key of the salt like below is it a good practice?

const N = 65536, r = 8, p = 1;
const dkLen = 32;

function hash(password, salty) {
	const passwordBuffer = new buffer.SlowBuffer(password.normalize('NFKC'));
	const saltBuffer = new buffer.SlowBuffer(salty.normalize('NFKC'));
	const saltKey = scrypt.syncScrypt(saltBuffer, saltBuffer, N, r, p, dkLen);

	const key = scrypt.syncScrypt(passwordBuffer, saltKey, N, r, p, dkLen);
	const hexKey = Buffer.from(key).toString('hex');
	const hexSalt = Buffer.from(saltKey).toString('hex');

	return hexKey+":"+hexSalt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant