-
Notifications
You must be signed in to change notification settings - Fork 69
/
test-sync.js
98 lines (74 loc) · 4.01 KB
/
test-sync.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*jslint node: true, indent: 4, stupid: true */
var bCrypt = require("./bCrypt");
console.log("\n\n Salts \n");
var salt1 = bCrypt.genSaltSync(8);
console.log(salt1);
var salt2 = bCrypt.genSaltSync(10);
console.log(salt2);
console.log("\n\n Hashes \n");
var hash1 = bCrypt.hashSync("super secret", salt1, null);
console.log(hash1);
var hash2 = bCrypt.hashSync("super secret", salt1, null);
console.log(hash2);
var hash3 = bCrypt.hashSync("supersecret", salt1, null);
console.log(hash3);
var hash4 = bCrypt.hashSync("supersecret", salt1, null);
console.log(hash4);
var hash5 = bCrypt.hashSync("super secret", salt2, null);
console.log(hash5);
var hash6 = bCrypt.hashSync("super secret", salt2, null);
console.log(hash6);
var hash7 = bCrypt.hashSync("supersecret", salt2, null);
console.log(hash7);
var hash8 = bCrypt.hashSync("supersecret", salt2, null);
console.log(hash8);
var hash9 = bCrypt.hashSync("super secret", null, null);
console.log(hash9);
var hash0 = bCrypt.hashSync("supersecret", null, null);
console.log(hash0);
console.log("\n\n First Set of Compares \n");
console.log(bCrypt.compareSync("super secret", hash1) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("super secret", hash2) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("super secret", hash5) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("super secret", hash6) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("super secret", hash9) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("super secret", hash3) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("super secret", hash4) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("super secret", hash7) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("super secret", hash8) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("super secret", hash0) ? 'FAILED' : 'PASSED');
console.log("\n\n Second Set of Compares \n");
console.log(bCrypt.compareSync("supersecret", hash1) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("supersecret", hash2) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("supersecret", hash5) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("supersecret", hash6) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("supersecret", hash9) ? 'FAILED' : 'PASSED');
console.log(bCrypt.compareSync("supersecret", hash3) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("supersecret", hash4) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("supersecret", hash7) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("supersecret", hash8) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync("supersecret", hash0) ? 'PASSED' : 'FAILED');
console.log('\n\n -------------------- UTF-8 passwords --------------------');
var pw1 = '\u6e2f', // http://www.fileformat.info/info/unicode/char/6e2f/index.htm
pw2 = '港', // Character 0x6e2f same as pw1.
pw3 = '\u6f2f', // http://www.fileformat.info/info/unicode/char/6f2f/index.htm
pw4 = '漯', // Character 0x6f2f same as pw3.
salt = '$2a$05$0000000000000000000000',
hash_pw1 = bCrypt.hashSync(pw1, salt, null),
hash_pw2 = bCrypt.hashSync(pw2, salt, null),
hash_pw3 = bCrypt.hashSync(pw3, salt, null),
hash_pw4 = bCrypt.hashSync(pw4, salt, null);
console.log("\n\n Hashes \n");
console.log(hash_pw1);
console.log(hash_pw2);
console.log(hash_pw3);
console.log(hash_pw4);
console.log("\n\n Third Set of Compares \n");
console.log(bCrypt.compareSync(pw1, hash_pw1) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync(pw2, hash_pw2) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync(pw3, hash_pw3) ? 'PASSED' : 'FAILED');
console.log(bCrypt.compareSync(pw4, hash_pw4) ? 'PASSED' : 'FAILED');
console.log('Hashes 1 and 3 are different: ' + (hash_pw1 !== hash_pw3 ? 'PASSED' : 'FAILED'));
console.log('Hashes 2 and 4 are different: ' + (hash_pw2 !== hash_pw4 ? 'PASSED' : 'FAILED'));
console.log('Hashes 1 and 2 are the same: ' + (hash_pw1 === hash_pw2 ? 'PASSED' : 'FAILED'));
console.log('Hashes 3 and 4 are the same: ' + (hash_pw3 === hash_pw4 ? 'PASSED' : 'FAILED'));