Skip to content

Commit 9c0e90f

Browse files
committed
Hid the profanity of some passwords; Now comparing using their encrypted hexes
1 parent 9dda379 commit 9c0e90f

File tree

7 files changed

+25
-10030
lines changed

7 files changed

+25
-10030
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
# Created by https://www.gitignore.io/api/node,laravel,bower,justcode,linux,osx,jetbrains,sublimetext,vim,xcode
33

4+
## My
5+
lab/
6+
47
### Node ###
58
# Logs
69
logs
@@ -88,7 +91,8 @@ bower_components
8891
.LSOverride
8992

9093
# Icon must end with two \r
91-
Icon
94+
Icon
95+
9296

9397
# Thumbnails
9498
._*

lib/config/stupidPasswords.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/helpers/radixTree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class RadixTree {
55
this.nodes = {};
66
this.stupidPasswords = stupidPasswords;
77
this.stupidPasswords.forEach(password => {
8-
this.addNode(password.password);
8+
this.addNode(password.hashedPassword);
99
});
1010
}
1111

lib/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
'use strict';
22

3+
const crypto = require('crypto');
34
const stupidPasswords = require('./config/stupidPasswords');
45
const RadixTree = require('./helpers/radixTree');
56
const passwordTree = new RadixTree(stupidPasswords);
67

7-
const isStupid = (userPasswordInputString) => passwordTree
8-
.searchForNodes(userPasswordInputString.toLowerCase());
8+
const isStupid = (userPasswordInputString) => {
9+
const userPassword = userPasswordInputString.toLowerCase();
10+
const userHashedPassword = crypto.createHash('sha1').update(userPassword).digest('hex');
11+
12+
return passwordTree.searchForNodes(userHashedPassword);
13+
}
914

1015
exports.isStupid = isStupid;
1116
exports.isOneOfThem = isStupid;
1217
exports.check = isStupid;
1318

1419
exports.rateOfUsage = (userPasswordInputString) => {
15-
const exists = passwordTree.searchForNodes(userPasswordInputString.toLowerCase());
16-
if (exists) {
17-
return stupidPasswords.find(password => password.password === userPasswordInputString.toLowerCase());
20+
const userPassword = userPasswordInputString.toLowerCase();
21+
const userHashedPassword = crypto.createHash('sha1').update(userPassword).digest('hex');
22+
23+
const passwordExists = passwordTree.searchForNodes(userHashedPassword);
24+
if (passwordExists) {
25+
const result = stupidPasswords.find(password => password.hashedPassword === userHashedPassword);
26+
result.password = userPassword;
27+
delete result.hashedPassword;
28+
return result;
1829
}
30+
1931
return {
2032
password: userPasswordInputString,
2133
frequency: 0,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stupid-passwords",
3-
"version": "0.0.6",
3+
"version": "0.0.8",
44
"description": "Guard your users from security problems that start by having stupid passwords",
55
"main": "index.js",
66
"scripts": {

resources/dumpProcessedPasswords.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)