Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
easy-pbkdf2
Advanced tools
Easy PBKDF2 makes it easier to create secure, individually salted, password hashes using PBKDF2.
This implementation is based on StackExchange's own Open Sourced PBKDF2 methods.
via cmd line:
$ npm install easy-pbkdf2 --save
or in your package.json
:
"dependencies": {
"easy-pbkdf2": "0.x.x"
}
var easyPbkdf2 = require("easy-pbkdf2")();
var salt = easyPbkdf2.generateSalt(); // `salt` should be treated as opaque, as it captures iterations
var password = "RandomDigits";
easyPbkdf2.secureHash( password, salt, function( err, passwordHash, originalSalt ) {
// use your own db's methods to save the hashed password AND salt.
currentUser.update({
// The Base64 encoded hash, 344 characters long
"password_hash": passwordHash,
// Salt length varies based on SALT_SIZE and iterations. The default SALT_SIZE of
// 32 produces a value that is:
// (hashIterations.toString(16).length) + 1 + base64EncodedSalt.length)
// characters long (42 characters).
"salt": originalSalt // === salt
});
});
// ...
// sometime later:
function authenticate( user, userEnteredPassword, callback ) {
// make sure the user-entered password is equal to the previously
// created hash when hashed with the same salt.
easyPbkdf2.verify( user.salt, user.password_hash, userEnteredPassword, function( err, valid ) {
callback( valid );
});
}
You can also use EasyPbkdf2 to generate the salt for you by omitting the salt
parameter:
easyPbkdf2.secureHash( password, function( err, passwordHash, newSalt ) {
// save newSalt somewhere!
});
To create a new instance of EasyPbkdf2
:
var easyPbkdf2 = require("easy-pbkdf2")();
You can also use the following methods of instantiation:
// the EasyPbkdf2 constructor
var EasyPbkdf2 = require("easy-pbkdf2"),
easyPbkdf2;
easyPbkdf2 = EasyPbkdf2(options);
easyPbkdf2 = new EasyPbkdf2(options);
easyPbkdf2 = EasyPbkdf2.EasyPbkdf2(options);
easyPbkdf2 = new EasyPbkdf2.EasyPbkdf2(options);
of which all will return an EasyPbkdf2
instance with options
set.
var options = {
// default DEFAULT_HASH_ITERATIONS is 512
"DEFAULT_HASH_ITERATIONS": 256,
// default SALT_SIZE is 32
"SALT_SIZE": 16,
// default KEY_LENGTH is 256
"KEY_LENGTH": 128
};
var easyPbkdf2 = new EasyPbkdf2(options);
console.log(easyPbkdf2.DEFAULT_HASH_ITERATIONS) // 256
console.log(easyPbkdf2.SALT_SIZE); // 16
console.log(easyPbkdf2.KEY_LENGTH); // 128
// options are applied to each instance individually.
console.log( (new EasyPbkdf2()).DEFAULT_HASH_ITERATIONS ); // 512
###weakHash( value )
Cranks out a collision resistant hash, relatively quickly. Not suitable for passwords, or sensitive information. Synchronous only
value
value
###random( bytes, callback )
Universal random provider. Generates cryptographically strong pseudo-random data. Syncronous or Asyncronous
###generateSalt( explicitIterations, callback )
Convenience wrapper around
.random
to grab a new salt value. Treat this value as opaque, as it captures iterations.Salt length varies based on SALT_SIZE and iterations. The default SALT_SIZE of 32 produces a value that is: (hashIterations.toString(16).length) + 1 + base64EncodedSalt.length) characters long (42 characters).
Synchronous or Asynchronous
###secureHash( value, salt, callback )
Alias for
hash
.
###hash( value, salt, callback )
Backs Secure hashes. Uses PBKDF2 internally, as implemented by node's native crypto library. See http://en.wikipedia.org/wiki/PBKDF2 and http://code.google.com/p/crypto-js/ for more information. Asynchronous only
###verify( salt, priorHash, value, callback )
Verifies that the supplied plaintext
value
hashes to the same base64 encoded string as thepriorHash
, when hashed with the same salt. This method uses a constant-time string equality check to ensure information is not leaked via timing-attack. Asynchronous only
value
matches the priorHash
, false if not. ).Please file them here: https://github.com/davidmurdoch/easy-pbkdf2/issues.
And remember: pull requests are very welcome. :-)
FAQs
Easily generate securily salted PBKDF2 hashes for password storage
The npm package easy-pbkdf2 receives a total of 647 weekly downloads. As such, easy-pbkdf2 popularity was classified as not popular.
We found that easy-pbkdf2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.