Skip to content

Commit c8fce7b

Browse files
committed
Updated code.
1 parent 407eada commit c8fce7b

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

index.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports.mustUpdateHashedPassword = function(hash_password, default_algori
2222
}
2323

2424
return true;
25-
}
25+
};
2626

2727

2828
module.exports.identifyHasher = function(hash_password) {
@@ -37,7 +37,7 @@ module.exports.identifyHasher = function(hash_password) {
3737
algorithm = hash_password.split('$')[0];
3838
}
3939
return algorithm;
40-
}
40+
};
4141

4242

4343
module.exports.getHasher = function(algorithm) {
@@ -86,7 +86,7 @@ module.exports.getHasher = function(algorithm) {
8686
return null;
8787
}
8888
}
89-
}
89+
};
9090

9191

9292
module.exports.Argon2PasswordHasher = function() {
@@ -136,7 +136,7 @@ module.exports.Argon2PasswordHasher = function() {
136136

137137
return false;
138138
}
139-
}
139+
};
140140

141141

142142
module.exports.PBKDF2PasswordHasher = function() {
@@ -187,7 +187,7 @@ module.exports.PBKDF2PasswordHasher = function() {
187187
const parts = hash_password.split('$');
188188
return parseInt(parts[1]) !== this.iterations;
189189
}
190-
}
190+
};
191191

192192

193193
module.exports.PBKDF2SHA1PasswordHasher = function() {
@@ -228,7 +228,7 @@ module.exports.PBKDF2SHA1PasswordHasher = function() {
228228
const dk = crypto.pbkdf2Sync(key, salt, parseInt(iterations), dkLen, 'sha1');
229229
return dk;
230230
}
231-
}
231+
};
232232

233233

234234
module.exports.BCryptSHA256PasswordHasher = function() {
@@ -262,7 +262,7 @@ module.exports.BCryptSHA256PasswordHasher = function() {
262262
const parts = hash_password.split('$');
263263
return parseInt(parts[3]) !== this.iterations;
264264
}
265-
}
265+
};
266266

267267

268268
module.exports.BCryptPasswordHasher = function() {
@@ -294,7 +294,7 @@ module.exports.BCryptPasswordHasher = function() {
294294
const parts = hash_password.split('$');
295295
return parseInt(parts[3]) !== this.iterations;
296296
}
297-
}
297+
};
298298

299299

300300
module.exports.SHA1PasswordHasher = function() {
@@ -326,7 +326,7 @@ module.exports.SHA1PasswordHasher = function() {
326326
this.mustUpdate = function(hash_password) {
327327
return false;
328328
}
329-
}
329+
};
330330

331331

332332
module.exports.MD5PasswordHasher = function() {
@@ -358,7 +358,7 @@ module.exports.MD5PasswordHasher = function() {
358358
this.mustUpdate = function(hash_password) {
359359
return false;
360360
}
361-
}
361+
};
362362

363363

364364
module.exports.UnsaltedSHA1PasswordHasher = function() {
@@ -388,13 +388,13 @@ module.exports.UnsaltedSHA1PasswordHasher = function() {
388388
this.mustUpdate = function(hash_password) {
389389
return false;
390390
}
391-
}
391+
};
392392

393393

394394
module.exports.UnsaltedMD5PasswordHasher = function() {
395395
this.algorithm = "unsalted_md5";
396396

397-
this.salt = function() {
397+
this.salt = () => {
398398
return '';
399399
}
400400

@@ -421,15 +421,15 @@ module.exports.UnsaltedMD5PasswordHasher = function() {
421421
this.mustUpdate = function(hash_password) {
422422
return false;
423423
}
424-
}
424+
};
425425

426426

427427
function generateRandomString(length) {
428428
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
429429
var result = '';
430430
for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
431431
return result;
432-
}
432+
};
433433

434434

435435

test/index.test.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,55 @@ describe('getHashers test with all hashing algorithms', () => {
77
it ('testing unsalted_md5', () => {
88
const hash_password = "5f4dcc3b5aa765d61d8327deb882cf99";
99
const h = hashers.identifyHasher(hash_password);
10-
assert.equal(h, 'unsalted_md5', 'Testing unsalted_md5 from Django');
10+
assert.strictEqual(h, 'unsalted_md5', 'Testing unsalted_md5 from Django');
1111
});
1212

1313
it ('testing unsalted_sha1', () => {
1414
const hash_password = "sha1$$5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8";
1515
const h = hashers.identifyHasher(hash_password);
16-
assert.equal(h, 'unsalted_sha1', 'Testing unsalted_sha1 from Django');
16+
assert.strictEqual(h, 'unsalted_sha1', 'Testing unsalted_sha1 from Django');
1717
});
1818

1919
it ('testing sha1', () => {
2020
const hash_password = "sha1$vCl9KSmkkKHJ$3864dc6b8ea10d757290660df171a0f7c5fc3b36";
2121
const h = hashers.identifyHasher(hash_password);
22-
assert.equal(h, 'sha1', 'Testing sha1 from Django');
22+
assert.strictEqual(h, 'sha1', 'Testing sha1 from Django');
2323
});
2424

2525
it ('testing md5', () => {
2626
const hash_password = "md5$UyDBYR3ttBkN$510f43d5da1a0ef16ed4ef361cbfef5e";
2727
const h = hashers.identifyHasher(hash_password);
28-
assert.equal(h, 'md5', 'Testing md5 from Django');
28+
assert.strictEqual(h, 'md5', 'Testing md5 from Django');
2929
});
3030

3131
it ('testing pbkdf2_sha256', () => {
3232
const hash_password = "pbkdf2_sha256$36000$c8SBx74kl0XA$bAmKN/CgJGlh7xpuxmvQX9ypsnjV68JqZlfLxWDYGBk=";
3333
const h = hashers.identifyHasher(hash_password);
34-
assert.equal(h, 'pbkdf2_sha256', 'Testing pbkdf2_sha256 from Django');
34+
assert.strictEqual(h, 'pbkdf2_sha256', 'Testing pbkdf2_sha256 from Django');
3535
});
3636

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

4343
it ('testing pbkdf2_sha1', () => {
4444
const hash_password = "pbkdf2_sha1$36000$P6Y4I7YXzZpB$LrWCTPqWtIdPFYY5jt+w56QJGR0=";
4545
const h = hashers.identifyHasher(hash_password);
46-
assert.equal(h, 'pbkdf2_sha1', 'Testing pbkdf2_sha1 from Django');
46+
assert.strictEqual(h, 'pbkdf2_sha1', 'Testing pbkdf2_sha1 from Django');
4747
});
4848

4949
it ('testing bcrypt_sha256', () => {
5050
const hash_password = "bcrypt_sha256$$2b$12$7swZEQstS0pPWpvL4LQ/guW75Lc8OCRY1V1zq17jUlsQqyLhVuzGa";
5151
const h = hashers.identifyHasher(hash_password);
52-
assert.equal(h, 'bcrypt_sha256', 'Testing bcrypt_sha256 from Django');
52+
assert.strictEqual(h, 'bcrypt_sha256', 'Testing bcrypt_sha256 from Django');
5353
});
5454

5555
it ('testing bcrypt', () => {
5656
const hash_password = "bcrypt$$2b$12$QssVJfXwb178/8i1CUMTsOoRhi7.oFF5FVdxbM1ZxCnd6iDfTZaVO";
5757
const h = hashers.identifyHasher(hash_password);
58-
assert.equal(h, 'bcrypt', 'Testing bcrypt from Django');
58+
assert.strictEqual(h, 'bcrypt', 'Testing bcrypt from Django');
5959
});
6060
});
6161

@@ -64,63 +64,63 @@ describe('Test all password hashing algorithms encode and verify methods', () =>
6464
const h = new hashers.UnsaltedMD5PasswordHasher();
6565
const hashPassword = await h.encode('password');
6666
const verify = await h.verify('password', hashPassword);
67-
assert.equal(verify, true, 'Testing unsalted_md5 encode and verify from Django');
67+
assert.strictEqual(verify, true, 'Testing unsalted_md5 encode and verify from Django');
6868
});
6969

7070
it ('testing unsalted_sha1 encode', async () => {
7171
const h = new hashers.UnsaltedSHA1PasswordHasher();
7272
const hashPassword = await h.encode('password');
7373
const verify = await h.verify('password', hashPassword);
74-
assert.equal(verify, true, 'Testing unsalted_sha1 encode and verify from Django');
74+
assert.strictEqual(verify, true, 'Testing unsalted_sha1 encode and verify from Django');
7575
});
7676

7777
it ('testing sha1 encode', async () => {
7878
const h = new hashers.SHA1PasswordHasher();
7979
const hashPassword = await h.encode('password');
8080
const verify = await h.verify('password', hashPassword);
81-
assert.equal(verify, true, 'Testing sha1 encode and verify from Django');
81+
assert.strictEqual(verify, true, 'Testing sha1 encode and verify from Django');
8282
});
8383

8484
it ('testing md5 encode', async () => {
8585
const h = new hashers.MD5PasswordHasher();
8686
const hashPassword = await h.encode('password');
8787
const verify = await h.verify('password', hashPassword);
88-
assert.equal(verify, true, 'Testing md5 encode and verify from Django');
88+
assert.strictEqual(verify, true, 'Testing md5 encode and verify from Django');
8989
});
9090

9191
it ('testing pbkdf2_sha256 encode', async () => {
9292
const h = new hashers.PBKDF2PasswordHasher();
9393
const hashPassword = await h.encode('password');
9494
const verify = await h.verify('password', hashPassword);
95-
assert.equal(verify, true, 'Testing pbkdf2_sha256 encode and verify from Django');
95+
assert.strictEqual(verify, true, 'Testing pbkdf2_sha256 encode and verify from Django');
9696
});
9797

9898
it ('testing argon2 encode', async () => {
9999
const h = new hashers.Argon2PasswordHasher();
100100
const hashPassword = await h.encode('password');
101101
const verify = await h.verify('password', hashPassword);
102-
assert.equal(verify, true, 'Testing argon2 encode and verify from Django');
102+
assert.strictEqual(verify, true, 'Testing argon2 encode and verify from Django');
103103
});
104104

105105
it ('testing pbkdf2_sha1 encode', async () => {
106106
const h = new hashers.PBKDF2SHA1PasswordHasher();
107107
const hashPassword = await h.encode('password');
108108
const verify = await h.verify('password', hashPassword);
109-
assert.equal(verify, true, 'Testing pbkdf2_sha1 encode and verify from Django');
109+
assert.strictEqual(verify, true, 'Testing pbkdf2_sha1 encode and verify from Django');
110110
});
111111

112112
it ('testing bcrypt_sha256 encode', async () => {
113113
const h = new hashers.BCryptSHA256PasswordHasher();
114114
const hashPassword = await h.encode('password');
115115
const verify = await h.verify('password', hashPassword);
116-
assert.equal(verify, true, 'Testing bcrypt_sha256 encode and verify from Django');
116+
assert.strictEqual(verify, true, 'Testing bcrypt_sha256 encode and verify from Django');
117117
});
118118

119119
it ('testing bcrypt encode', async () => {
120120
const h = new hashers.BCryptPasswordHasher();
121121
const hashPassword = await h.encode('password');
122122
const verify = await h.verify('password', hashPassword);
123-
assert.equal(verify, true, 'Testing bcrypt encode and verify from Django');
123+
assert.strictEqual(verify, true, 'Testing bcrypt encode and verify from Django');
124124
});
125125
});
126126

0 commit comments

Comments
 (0)