Skip to content

Instantly share code, notes, and snippets.

@pierreis
pierreis / hash.js
Last active September 24, 2018 21:09
How to generate and check strong binary hashes for passwords with Node.JS
/*!
* Password hashing
*
* In essence, passwords are hashed with a global salt (the same for every password), which is
* to remain secret, and a local salt (only specific to one password). If you don't provide
* local salt to `hashPassword`, it will generate one for you.
* The result is a 48-byte long buffer which includes your hashed password along with the local
* salt in clear, that you can store in your DB. You may call buffer.toString('hex') in case
* you want to store it as hex and waste space.
*