UNPKG

4.21 kBJavaScriptView Raw
1/*jslint node: true, indent: 4, stupid: true */
2var bCrypt = require("./bCrypt");
3
4console.log("\n\n Salts \n");
5
6var salt1 = bCrypt.genSaltSync(8);
7console.log(salt1);
8
9var salt2 = bCrypt.genSaltSync(10);
10console.log(salt2);
11
12
13console.log("\n\n Hashes \n");
14
15var hash1 = bCrypt.hashSync("super secret", salt1, null);
16console.log(hash1);
17
18var hash2 = bCrypt.hashSync("super secret", salt1, null);
19console.log(hash2);
20
21var hash3 = bCrypt.hashSync("supersecret", salt1, null);
22console.log(hash3);
23
24var hash4 = bCrypt.hashSync("supersecret", salt1, null);
25console.log(hash4);
26
27var hash5 = bCrypt.hashSync("super secret", salt2, null);
28console.log(hash5);
29
30var hash6 = bCrypt.hashSync("super secret", salt2, null);
31console.log(hash6);
32
33var hash7 = bCrypt.hashSync("supersecret", salt2, null);
34console.log(hash7);
35
36var hash8 = bCrypt.hashSync("supersecret", salt2, null);
37console.log(hash8);
38
39var hash9 = bCrypt.hashSync("super secret", null, null);
40console.log(hash9);
41
42var hash0 = bCrypt.hashSync("supersecret", null, null);
43console.log(hash0);
44
45console.log("\n\n First Set of Compares \n");
46
47console.log(bCrypt.compareSync("super secret", hash1) ? 'PASSED' : 'FAILED');
48console.log(bCrypt.compareSync("super secret", hash2) ? 'PASSED' : 'FAILED');
49console.log(bCrypt.compareSync("super secret", hash5) ? 'PASSED' : 'FAILED');
50console.log(bCrypt.compareSync("super secret", hash6) ? 'PASSED' : 'FAILED');
51console.log(bCrypt.compareSync("super secret", hash9) ? 'PASSED' : 'FAILED');
52console.log(bCrypt.compareSync("super secret", hash3) ? 'FAILED' : 'PASSED');
53console.log(bCrypt.compareSync("super secret", hash4) ? 'FAILED' : 'PASSED');
54console.log(bCrypt.compareSync("super secret", hash7) ? 'FAILED' : 'PASSED');
55console.log(bCrypt.compareSync("super secret", hash8) ? 'FAILED' : 'PASSED');
56console.log(bCrypt.compareSync("super secret", hash0) ? 'FAILED' : 'PASSED');
57
58console.log("\n\n Second Set of Compares \n");
59
60console.log(bCrypt.compareSync("supersecret", hash1) ? 'FAILED' : 'PASSED');
61console.log(bCrypt.compareSync("supersecret", hash2) ? 'FAILED' : 'PASSED');
62console.log(bCrypt.compareSync("supersecret", hash5) ? 'FAILED' : 'PASSED');
63console.log(bCrypt.compareSync("supersecret", hash6) ? 'FAILED' : 'PASSED');
64console.log(bCrypt.compareSync("supersecret", hash9) ? 'FAILED' : 'PASSED');
65console.log(bCrypt.compareSync("supersecret", hash3) ? 'PASSED' : 'FAILED');
66console.log(bCrypt.compareSync("supersecret", hash4) ? 'PASSED' : 'FAILED');
67console.log(bCrypt.compareSync("supersecret", hash7) ? 'PASSED' : 'FAILED');
68console.log(bCrypt.compareSync("supersecret", hash8) ? 'PASSED' : 'FAILED');
69console.log(bCrypt.compareSync("supersecret", hash0) ? 'PASSED' : 'FAILED');
70
71
72console.log('\n\n -------------------- UTF-8 passwords --------------------');
73var pw1 = '\u6e2f', // http://www.fileformat.info/info/unicode/char/6e2f/index.htm
74 pw2 = '港', // Character 0x6e2f same as pw1.
75 pw3 = '\u6f2f', // http://www.fileformat.info/info/unicode/char/6f2f/index.htm
76 pw4 = '漯', // Character 0x6f2f same as pw3.
77 salt = '$2a$05$0000000000000000000000',
78 hash_pw1 = bCrypt.hashSync(pw1, salt, null),
79 hash_pw2 = bCrypt.hashSync(pw2, salt, null),
80 hash_pw3 = bCrypt.hashSync(pw3, salt, null),
81 hash_pw4 = bCrypt.hashSync(pw4, salt, null);
82
83console.log("\n\n Hashes \n");
84console.log(hash_pw1);
85console.log(hash_pw2);
86console.log(hash_pw3);
87console.log(hash_pw4);
88
89console.log("\n\n Third Set of Compares \n");
90
91console.log(bCrypt.compareSync(pw1, hash_pw1) ? 'PASSED' : 'FAILED');
92console.log(bCrypt.compareSync(pw2, hash_pw2) ? 'PASSED' : 'FAILED');
93console.log(bCrypt.compareSync(pw3, hash_pw3) ? 'PASSED' : 'FAILED');
94console.log(bCrypt.compareSync(pw4, hash_pw4) ? 'PASSED' : 'FAILED');
95console.log('Hashes 1 and 3 are different: ' + (hash_pw1 !== hash_pw3) ? 'PASSED' : 'FAILED');
96console.log('Hashes 2 and 4 are different: ' + (hash_pw2 !== hash_pw4) ? 'PASSED' : 'FAILED');
97console.log('Hashes 1 and 2 are the same: ' + (hash_pw1 !== hash_pw2) ? 'PASSED' : 'FAILED');
98console.log('Hashes 3 and 4 are the same: ' + (hash_pw3 !== hash_pw4) ? 'PASSED' : 'FAILED');