Comparing version 0.1.2 to 0.1.3
17
index.js
@@ -1,2 +0,3 @@ | ||
var bindings = require("bindings")("argon2_lib"); | ||
var bindings = require("bindings")("argon2_lib"), | ||
crypto = require("crypto"); | ||
@@ -26,2 +27,16 @@ exports.encrypt = function (plain, salt, callback) { | ||
exports.generateSalt = function (callback) { | ||
"use strict"; | ||
crypto.randomBytes(16, function (err, buffer) { | ||
callback(err, buffer.toString()); | ||
}); | ||
}; | ||
exports.generateSaltSync = function () { | ||
"use strict"; | ||
return crypto.randomBytes(16).toString(); | ||
}; | ||
exports.verify = function (encrypted, plain, callback) { | ||
@@ -28,0 +43,0 @@ "use strict"; |
{ | ||
"name": "argon2", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "An Argon2 library for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,4 +6,4 @@ # node-argon2 [![NPM package][npm-image]][npm-url] [![Build status][travis-image]][travis-url] [![Code Climate][codeclimate-image]][codeclimate-url] [![Dependencies][david-dm-image]][david-dm-url] | ||
### Usage | ||
Currently, only the encrypt and verify methods are implemented for Argon2i, | ||
asynchronously. | ||
Currently, only the encrypt and verify methods are implemented for Argon2i, and a method to generate cryptographically | ||
safe random salts. | ||
@@ -14,3 +14,3 @@ To hash a password: | ||
argon2.encrypt('password', 'somesalt', function(err, hash) { | ||
argon2.encrypt('password', 'somesalt', function (err, hash) { | ||
if (err) // encryption failure | ||
@@ -21,5 +21,27 @@ throw err; | ||
}); | ||
// OR | ||
try { | ||
var hash = argon2.encryptSync('password', 'somesalt'); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
``` | ||
Resultant hashes will be 90 characters long. | ||
You can provide your own salt as the second parameter. It is recommended to use | ||
the salt generating methods instead of a hardcoded, constant salt: | ||
```js | ||
var argon2 = require('argon2'); | ||
argon2.generateSalt(function (salt) { | ||
doSomethingWith(salt); | ||
}); | ||
// OR | ||
var salt = argon2.generateSaltSync(); | ||
``` | ||
To verify a password: | ||
@@ -29,3 +51,3 @@ ```js | ||
argon2.verify('<big long hash>', 'password', function(err) { | ||
argon2.verify('<big long hash>', 'password', function (err) { | ||
if (err) // password did not match | ||
@@ -36,2 +58,10 @@ throw err; | ||
}); | ||
// OR | ||
if (argon2.verifySync('<big long hash>', 'password')) { | ||
authenticate(); | ||
} else { | ||
fail(); | ||
} | ||
``` | ||
@@ -38,0 +68,0 @@ First parameter must have been generated by an Argon2 encoded hashing method, |
@@ -38,3 +38,3 @@ var argon2 = require('.'); | ||
assert.equal(hash, "$argon2i$m=4096,t=3,p=1$c29tZXNhbHQAAAAAAAAAAA$FHF/OZ0GJpMRAlBmPTqXxw36Ftp87JllALZPcP9w9gs", | ||
"Hash should be equal to expected."); | ||
"Hash should be equal to expected."); | ||
assert.done(); | ||
@@ -48,3 +48,3 @@ }, | ||
assert.throws(function() { | ||
assert.throws(function () { | ||
argon2.encryptSync("password", "somesaltwaytoobig") | ||
@@ -55,2 +55,22 @@ }, Error, "Error should be thrown."); | ||
test_generate_salt: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
argon2.generateSalt(function (err, salt) { | ||
assert.ok(salt.length <= 16, "Generated salt length should be less than 16."); | ||
assert.done(); | ||
}); | ||
}, | ||
test_generate_salt_sync: function (assert) { | ||
"use strict"; | ||
assert.expect(1); | ||
assert.ok(argon2.generateSaltSync().length <= 16, "Generated salt length should be less than 16."); | ||
assert.done(); | ||
}, | ||
test_verify_ok: function (assert) { | ||
@@ -57,0 +77,0 @@ "use strict"; |
Sorry, the diff of this file is not supported yet
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
1720911
127
79