1 | var bCrypt = require("./bCrypt");
|
2 |
|
3 | var compares = 0;
|
4 | var salts = [];
|
5 | var hashes = [];
|
6 |
|
7 | console.log("\n\n Salts \n");
|
8 | bCrypt.genSalt(8, saltCallback);
|
9 | bCrypt.genSalt(10, saltCallback);
|
10 |
|
11 | function saltCallback(error, result) {
|
12 | if(!error) {
|
13 | console.log(result);
|
14 | } else {
|
15 | console.log(error);
|
16 | }
|
17 | salts.push(result);
|
18 | if(salts.length == 2) {
|
19 | console.log("\n\n Hashes \n");
|
20 | createHash(salts[0]);
|
21 | }
|
22 | }
|
23 |
|
24 | function createHash(salt) {
|
25 | bCrypt.hash("bacon", salt, null, hashCallback);
|
26 | bCrypt.hash("bacon", salt, null, hashCallback);
|
27 | }
|
28 |
|
29 | function hashCallback(error, result) {
|
30 | if(!error) {
|
31 | console.log(result);
|
32 | } else {
|
33 | console.log(error);
|
34 | }
|
35 | hashes.push(result);
|
36 | if(hashes.length == 2) {
|
37 | createHash(salts[1]);
|
38 | } else if(hashes.length == 4) {
|
39 | console.log("\n\n True Compares \n");
|
40 | compares = 0;
|
41 | startCompares("bacon", trueCompareCallback);
|
42 | }
|
43 | }
|
44 |
|
45 | function startCompares(string, callback) {
|
46 | bCrypt.compare(string, hashes[0], callback);
|
47 | bCrypt.compare(string, hashes[1], callback);
|
48 | bCrypt.compare(string, hashes[2], callback);
|
49 | bCrypt.compare(string, hashes[3], callback);
|
50 | }
|
51 |
|
52 | function trueCompareCallback(error, result) {
|
53 | if(!error) {
|
54 | console.log(result);
|
55 | } else {
|
56 | console.log(error);
|
57 | }
|
58 | if(++compares == 4) {
|
59 | console.log("\n\n False Compares \n");
|
60 | compares = 0;
|
61 | startCompares("veggies", falseCompareCallback);
|
62 | }
|
63 | }
|
64 |
|
65 | function falseCompareCallback(error, result) {
|
66 | if(!error) {
|
67 | console.log(result);
|
68 | } else {
|
69 | console.log(error);
|
70 | }
|
71 | } |
\ | No newline at end of file |