Skip to content
Open

Main #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ All password hashing algorithms for Django implemented in javascript for nodejs
6. MD5PasswordHasher
7. UnsaltedSHA1PasswordHasher
8. UnsaltedMD5PasswordHasher
9. Argon2PasswordHasher

# Usage

Expand Down
56 changes: 0 additions & 56 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

const bcrypt = require('bcryptjs');
const crypto = require('crypto');
const argon2 = require('argon2-ffi').argon2i;
const util = require('util');
const randomBytes = util.promisify(crypto.randomBytes);

Expand Down Expand Up @@ -50,10 +49,6 @@ module.exports.getHasher = function(algorithm) {
return new this.PBKDF2PasswordHasher();
}

case "argon2": {
return new this.Argon2PasswordHasher();
}

case "pbkdf2_sha1": {
return new this.PBKDF2SHA1PasswordHasher();
}
Expand Down Expand Up @@ -88,57 +83,6 @@ module.exports.getHasher = function(algorithm) {
}
};


module.exports.Argon2PasswordHasher = function() {
this.algorithm = "argon2";
this.version = 19;
this.time_cost = 2;
this.memory_cost = 512;
this.parallelism_value = 2;
this.hash_length = 16;

this.salt = async function() {
return await randomBytes(32)
}

this.encode = async function(password) {
const options = {
timeCost: this.time_cost,
memoryCost: this.memory_cost,
parallelism: this.parallelism_value,
hashLength: this.hash_length
};

const salt = await this.salt();
const hash = await argon2.hash(password, salt, options);
return this.algorithm + hash;
}

this.verify = async function(password, hash_password) {
hash_password = hash_password.substring(this.algorithm.length, hash_password.length);
return await argon2.verify(hash_password, password);
}

this.mustUpdate = function(hash_password) {
const parts = hash_password.split('$');
if (parts[0] !== this.algorithm) {
return true;
}

if (parts[2] !== this.version) {
return true;
}

const options = "m=" + this.memory_cost + ",t=" + this.time_cost + ",p=" + this.parallelism_value;
if (options !== parts[3]) {
return true;
}

return false;
}
};


module.exports.PBKDF2PasswordHasher = function() {
this.algorithm = "pbkdf2_sha256";
this.iterations = 120000;
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "node-django-hashers",
"version": "1.1.6",
"dependencies": {
"argon2-ffi": "^1.1.0",
"assert": "^1.4.1",
"bcryptjs": "^2.3.0",
"node-gyp": "^3.7.0"
Expand Down
15 changes: 1 addition & 14 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ describe('getHashers test with all hashing algorithms', () => {
assert.strictEqual(h, 'pbkdf2_sha256', 'Testing pbkdf2_sha256 from Django');
});

it ('testing argon2', () => {
const hash_password = "argon2$argon2i$v=19$m=512,t=2,p=2$UXZPOFhoSUxrWmhQ$CCPcRG8t+LOJB8H1zL+Prw";
const h = hashers.identifyHasher(hash_password);
assert.strictEqual(h, 'argon2', 'Testing argon2 from Django');
});

it ('testing pbkdf2_sha1', () => {
const hash_password = "pbkdf2_sha1$36000$P6Y4I7YXzZpB$LrWCTPqWtIdPFYY5jt+w56QJGR0=";
const h = hashers.identifyHasher(hash_password);
Expand Down Expand Up @@ -94,14 +88,7 @@ describe('Test all password hashing algorithms encode and verify methods', () =>
const verify = await h.verify('password', hashPassword);
assert.strictEqual(verify, true, 'Testing pbkdf2_sha256 encode and verify from Django');
});

it ('testing argon2 encode', async () => {
const h = new hashers.Argon2PasswordHasher();
const hashPassword = await h.encode('password');
const verify = await h.verify('password', hashPassword);
assert.strictEqual(verify, true, 'Testing argon2 encode and verify from Django');
});


it ('testing pbkdf2_sha1 encode', async () => {
const h = new hashers.PBKDF2SHA1PasswordHasher();
const hashPassword = await h.encode('password');
Expand Down