1 |
|
2 | var bCrypt = require("./bCrypt");
|
3 |
|
4 | console.log("\n\n Salts \n");
|
5 |
|
6 | var salt1 = bCrypt.genSaltSync(8);
|
7 | console.log(salt1);
|
8 |
|
9 | var salt2 = bCrypt.genSaltSync(10);
|
10 | console.log(salt2);
|
11 |
|
12 |
|
13 | console.log("\n\n Hashes \n");
|
14 |
|
15 | var hash1 = bCrypt.hashSync("super secret", salt1, null);
|
16 | console.log(hash1);
|
17 |
|
18 | var hash2 = bCrypt.hashSync("super secret", salt1, null);
|
19 | console.log(hash2);
|
20 |
|
21 | var hash3 = bCrypt.hashSync("supersecret", salt1, null);
|
22 | console.log(hash3);
|
23 |
|
24 | var hash4 = bCrypt.hashSync("supersecret", salt1, null);
|
25 | console.log(hash4);
|
26 |
|
27 | var hash5 = bCrypt.hashSync("super secret", salt2, null);
|
28 | console.log(hash5);
|
29 |
|
30 | var hash6 = bCrypt.hashSync("super secret", salt2, null);
|
31 | console.log(hash6);
|
32 |
|
33 | var hash7 = bCrypt.hashSync("supersecret", salt2, null);
|
34 | console.log(hash7);
|
35 |
|
36 | var hash8 = bCrypt.hashSync("supersecret", salt2, null);
|
37 | console.log(hash8);
|
38 |
|
39 | var hash9 = bCrypt.hashSync("super secret", null, null);
|
40 | console.log(hash9);
|
41 |
|
42 | var hash0 = bCrypt.hashSync("supersecret", null, null);
|
43 | console.log(hash0);
|
44 |
|
45 | console.log("\n\n First Set of Compares \n");
|
46 |
|
47 | console.log(bCrypt.compareSync("super secret", hash1) ? 'PASSED' : 'FAILED');
|
48 | console.log(bCrypt.compareSync("super secret", hash2) ? 'PASSED' : 'FAILED');
|
49 | console.log(bCrypt.compareSync("super secret", hash5) ? 'PASSED' : 'FAILED');
|
50 | console.log(bCrypt.compareSync("super secret", hash6) ? 'PASSED' : 'FAILED');
|
51 | console.log(bCrypt.compareSync("super secret", hash9) ? 'PASSED' : 'FAILED');
|
52 | console.log(bCrypt.compareSync("super secret", hash3) ? 'FAILED' : 'PASSED');
|
53 | console.log(bCrypt.compareSync("super secret", hash4) ? 'FAILED' : 'PASSED');
|
54 | console.log(bCrypt.compareSync("super secret", hash7) ? 'FAILED' : 'PASSED');
|
55 | console.log(bCrypt.compareSync("super secret", hash8) ? 'FAILED' : 'PASSED');
|
56 | console.log(bCrypt.compareSync("super secret", hash0) ? 'FAILED' : 'PASSED');
|
57 |
|
58 | console.log("\n\n Second Set of Compares \n");
|
59 |
|
60 | console.log(bCrypt.compareSync("supersecret", hash1) ? 'FAILED' : 'PASSED');
|
61 | console.log(bCrypt.compareSync("supersecret", hash2) ? 'FAILED' : 'PASSED');
|
62 | console.log(bCrypt.compareSync("supersecret", hash5) ? 'FAILED' : 'PASSED');
|
63 | console.log(bCrypt.compareSync("supersecret", hash6) ? 'FAILED' : 'PASSED');
|
64 | console.log(bCrypt.compareSync("supersecret", hash9) ? 'FAILED' : 'PASSED');
|
65 | console.log(bCrypt.compareSync("supersecret", hash3) ? 'PASSED' : 'FAILED');
|
66 | console.log(bCrypt.compareSync("supersecret", hash4) ? 'PASSED' : 'FAILED');
|
67 | console.log(bCrypt.compareSync("supersecret", hash7) ? 'PASSED' : 'FAILED');
|
68 | console.log(bCrypt.compareSync("supersecret", hash8) ? 'PASSED' : 'FAILED');
|
69 | console.log(bCrypt.compareSync("supersecret", hash0) ? 'PASSED' : 'FAILED');
|
70 |
|
71 |
|
72 | console.log('\n\n -------------------- UTF-8 passwords --------------------');
|
73 | var pw1 = '\u6e2f',
|
74 | pw2 = '港',
|
75 | pw3 = '\u6f2f',
|
76 | pw4 = '漯',
|
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 |
|
83 | console.log("\n\n Hashes \n");
|
84 | console.log(hash_pw1);
|
85 | console.log(hash_pw2);
|
86 | console.log(hash_pw3);
|
87 | console.log(hash_pw4);
|
88 |
|
89 | console.log("\n\n Third Set of Compares \n");
|
90 |
|
91 | console.log(bCrypt.compareSync(pw1, hash_pw1) ? 'PASSED' : 'FAILED');
|
92 | console.log(bCrypt.compareSync(pw2, hash_pw2) ? 'PASSED' : 'FAILED');
|
93 | console.log(bCrypt.compareSync(pw3, hash_pw3) ? 'PASSED' : 'FAILED');
|
94 | console.log(bCrypt.compareSync(pw4, hash_pw4) ? 'PASSED' : 'FAILED');
|
95 | console.log('Hashes 1 and 3 are different: ' + (hash_pw1 !== hash_pw3) ? 'PASSED' : 'FAILED');
|
96 | console.log('Hashes 2 and 4 are different: ' + (hash_pw2 !== hash_pw4) ? 'PASSED' : 'FAILED');
|
97 | console.log('Hashes 1 and 2 are the same: ' + (hash_pw1 !== hash_pw2) ? 'PASSED' : 'FAILED');
|
98 | console.log('Hashes 3 and 4 are the same: ' + (hash_pw3 !== hash_pw4) ? 'PASSED' : 'FAILED');
|