Skip to content

Commit

Permalink
Added unit tests and updated syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kalvish21 committed Aug 11, 2018
1 parent 2d29cff commit 5acedee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ All password hashing algorithms for Django implemented in javascript for nodejs
A simple example just verifying and creating Django compatible passwords:

```javascript
var hashers = require('node-django-hashers');
const hashers = require('node-django-hashers');

var h = new hashers.PBKDF2PasswordHasher();
const h = new hashers.PBKDF2PasswordHasher();
h.encode("password").then(console.log); // prints the hashed password
```

Expand Down
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports.PBKDF2PasswordHasher = function() {

this.mustUpdate = function(hash_password) {
var parts = hash_password.split('$');
return parseInt(parts[1]) != this.iterations;
return parseInt(parts[1]) !== this.iterations;
}

// Below code is from node-pbkdf2
Expand Down Expand Up @@ -248,17 +248,17 @@ module.exports.PBKDF2SHA1PasswordHasher = function() {
var iterations = parseInt(parts[1]);
var salt = parts[2];
var value = self.pbkdf2(password, salt, iterations, self.len).toString('base64');
resolve(value == parts[3]);
resolve(value === parts[3]);
});
}

this.mustUpdate = function(hash_password) {
var parts = hash_password.split('$');
return parseInt(parts[1]) != this.iterations;
return parseInt(parts[1]) !== this.iterations;
}

this.pbkdf2 = function(key, salt, iterations, dkLen) {
var dk = crypto.pbkdf2Sync(key, salt, parseInt(iterations), dkLen, 'sha1');
const dk = crypto.pbkdf2Sync(key, salt, parseInt(iterations), dkLen, 'sha1');
return dk;
}
}
Expand Down Expand Up @@ -294,7 +294,7 @@ module.exports.BCryptSHA256PasswordHasher = function() {

this.mustUpdate = function(hash_password) {
var parts = hash_password.split('$');
return parseInt(parts[3]) != this.iterations;
return parseInt(parts[3]) !== this.iterations;
}
}

Expand Down Expand Up @@ -327,7 +327,7 @@ module.exports.BCryptPasswordHasher = function() {

this.mustUpdate = function(hash_password) {
var parts = hash_password.split('$');
return parseInt(parts[3]) != this.iterations;
return parseInt(parts[3]) !== this.iterations;
}
}

Expand All @@ -354,7 +354,7 @@ module.exports.SHA1PasswordHasher = function() {
var parts = hash_password.split('$');
var compare = self.algorithm + "$" + parts[1] + "$" +
crypto.createHash('sha1').update(parts[1] + password).digest("hex");
resolve(compare == hash_password);
resolve(compare === hash_password);
});
}

Expand Down Expand Up @@ -448,7 +448,7 @@ module.exports.UnsaltedMD5PasswordHasher = function() {
hash_password = hash_password.substring(5, 37);
}
var compare = crypto.createHash('md5').update(password + self.salt()).digest("hex");
resolve(compare == hash_password);
resolve(compare === hash_password);
});

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-django-hashers",
"version": "1.1.2",
"version": "1.1.3",
"dependencies": {
"argon2-ffi": "^1.1.0",
"assert": "^1.4.1",
Expand Down

0 comments on commit 5acedee

Please sign in to comment.