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