Last active
August 13, 2019 11:59
-
-
Save rkleine/eeeb43248daacedf45e85b8a3e90ac10 to your computer and use it in GitHub Desktop.
CouchDB 2.x NodeJS password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto') | |
function generatePassword(password, options = {}) { | |
const { iterations = 1000, keylen = 20, digest = 'sha1', saltSize = 24 } = options | |
const salt = crypto.randomBytes(saltSize).toString('hex') | |
const key = crypto.pbkdf2Sync(password, salt, iterations, keylen, digest).toString('hex') | |
return { | |
iterations, | |
salt, | |
key | |
} | |
} | |
console.log(generatePassword('my password')) | |
/* output | |
{ | |
iterations: 1000, | |
salt: '87c61b8c12614abd37038769b1caa91f11f22efeea17a238', | |
key: '4251927518165a19f9aa6e459d7665e5fa7ef559' | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment