pbkdf2-wrapper
Advanced tools
Comparing version 1.3.4 to 2.0.0
const crypto = require('crypto'); | ||
const righto = require('righto'); | ||
const { promisify } = require('util'); | ||
const defaultConfig = require('./defaultConfig'); | ||
const randomBytes = promisify(crypto.randomBytes); | ||
const pbkdf2 = promisify(crypto.pbkdf2); | ||
function generateHash (config, hash, salt) { | ||
@@ -17,8 +21,3 @@ const combined = Buffer.alloc(hash.length + salt.length + 8); | ||
function hashText (text, config, callback) { | ||
if (arguments.length === 2) { | ||
callback = config; | ||
config = defaultConfig; | ||
} | ||
async function hashText (text, config) { | ||
config = { | ||
@@ -29,15 +28,7 @@ ...defaultConfig, | ||
const salt = righto(crypto.randomBytes, config.saltBytes); | ||
const hash = righto(crypto.pbkdf2, text, salt, config.iterations, config.hashBytes, config.digest); | ||
const hashedPassword = righto.sync(generateHash, config, hash, salt); | ||
hashedPassword(callback); | ||
const salt = await randomBytes(config.saltBytes); | ||
const hash = await pbkdf2(text, salt, config.iterations, config.hashBytes, config.digest); | ||
return generateHash(config, hash, salt); | ||
} | ||
module.exports = (...args) => { | ||
if (typeof args[args.length - 1] === 'function') { | ||
return hashText(...args); | ||
} else { | ||
return righto(hashText, ...args); | ||
} | ||
}; | ||
module.exports = hashText; |
{ | ||
"name": "pbkdf2-wrapper", | ||
"version": "1.3.4", | ||
"version": "2.0.0", | ||
"description": "A wrapper around the inbuilt pbkdf2 crypto function for password hashing", | ||
@@ -37,9 +37,6 @@ "keywords": [ | ||
"homepage": "https://github.com/markwylde/pbkdf2-wrapper#readme", | ||
"dependencies": { | ||
"righto": "^6.1.3" | ||
}, | ||
"devDependencies": { | ||
"basictap": "^1.3.1", | ||
"basictap": "^2.0.1", | ||
"c8": "^7.7.3" | ||
} | ||
} |
@@ -15,4 +15,4 @@ # pbkdf2-wrapper | ||
```javascript | ||
const hashText = require('pbkdf2-wrapper/hashText') | ||
const verifyHash = require('pbkdf2-wrapper/verifyHash') | ||
import hashText from 'pbkdf2-wrapper/hashText'; | ||
import verifyHash from 'pbkdf2-wrapper/verifyHash'; | ||
@@ -26,18 +26,6 @@ // config is optional, if not passed will use the following as defaults | ||
iterations: 372791 | ||
} | ||
}; | ||
// Promises | ||
const password = await hashText('test-password', config) | ||
const equality = await verifyHash('test-password', password, config) | ||
// Callbacks | ||
hashText('test-password', config, function (error, hash){}) | ||
verifyHash('test-password', password, config, function (err, equality){}) | ||
// Deferred callbacks | ||
const hashPassword = hashText('test-password', config) | ||
hashPassword(function (error, hash){}) | ||
const verifyPassword = verifyHash('test-password', password) | ||
verifyPassword(function (err, equality){}) | ||
const hash = await hashText('test-password', config); | ||
const equality = await verifyHash('test-password', hash, config); | ||
``` | ||
@@ -44,0 +32,0 @@ |
const crypto = require('crypto'); | ||
const righto = require('righto'); | ||
const { promisify } = require('util'); | ||
const defaultConfig = require('./defaultConfig'); | ||
const pbkdf2 = promisify(crypto.pbkdf2); | ||
@@ -9,8 +11,3 @@ function checkHash (verifyHash, hash) { | ||
function verifyHash (text, combined, config, callback) { | ||
if (arguments.length === 3) { | ||
callback = config; | ||
config = {}; | ||
} | ||
async function verifyHash (text, combined, config) { | ||
config = { | ||
@@ -28,14 +25,6 @@ ...defaultConfig, | ||
const verifyHash = righto(crypto.pbkdf2, text, salt, iterations, hashBytes, config.digest); | ||
const verified = righto.sync(checkHash, verifyHash, hash); | ||
verified(callback); | ||
const verifyHash = await pbkdf2(text, salt, iterations, hashBytes, config.digest); | ||
return checkHash(verifyHash, hash); | ||
} | ||
module.exports = (...args) => { | ||
if (typeof args[args.length - 1] === 'function') { | ||
return verifyHash(...args); | ||
} else { | ||
return righto(verifyHash, ...args); | ||
} | ||
}; | ||
module.exports = verifyHash; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
5024
58
33
- Removedrighto@^6.1.3
- Removedabbott@1.1.3(transitive)
- Removedrighto@6.1.3(transitive)
- Removedsetimmediate@1.0.5(transitive)