|
| 1 | +// Copyright (c) 2023, Sudipto Chandra |
| 2 | +// All rights reserved. Check LICENSE file for details. |
| 3 | + |
| 4 | +import 'dart:convert'; |
| 5 | + |
| 6 | +import 'package:hashlib/hashlib.dart'; |
| 7 | +import 'package:test/test.dart'; |
| 8 | + |
| 9 | +void main() { |
| 10 | + // https://github.com/pyca/bcrypt/blob/main/tests/test_bcrypt.py |
| 11 | + group('bcrypt version 2b', () { |
| 12 | + test(r"$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm", () { |
| 13 | + var password = "Kk4DQuMMfZL9o"; |
| 14 | + var encoded = |
| 15 | + r"$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm"; |
| 16 | + var output = bcrypt(utf8.encode(password), encoded); |
| 17 | + expect(output, equals(encoded)); |
| 18 | + }); |
| 19 | + |
| 20 | + test(r"$2b$04$pQ7gRO7e6wx/936oXhNjrOUNOHL1D0h1N2IDbJZYs.1ppzSof6SPy", () { |
| 21 | + var password = "9IeRXmnGxMYbs"; |
| 22 | + var encoded = |
| 23 | + r"$2b$04$pQ7gRO7e6wx/936oXhNjrOUNOHL1D0h1N2IDbJZYs.1ppzSof6SPy"; |
| 24 | + var output = bcrypt(utf8.encode(password), encoded); |
| 25 | + expect(output, equals(encoded)); |
| 26 | + }); |
| 27 | + |
| 28 | + test(r"$2b$04$SQe9knOzepOVKoYXo9xTteNYr6MBwVz4tpriJVe3PNgYufGIsgKcW", () { |
| 29 | + var password = "xVQVbwa1S0M8r"; |
| 30 | + var encoded = |
| 31 | + r"$2b$04$SQe9knOzepOVKoYXo9xTteNYr6MBwVz4tpriJVe3PNgYufGIsgKcW"; |
| 32 | + var output = bcrypt(utf8.encode(password), encoded); |
| 33 | + expect(output, equals(encoded)); |
| 34 | + }); |
| 35 | + |
| 36 | + test(r"$2b$04$eH8zX.q5Q.j2hO1NkVYJQOM6KxntS/ow3.YzVmFrE4t//CoF4fvne", () { |
| 37 | + var password = "Zfgr26LWd22Za"; |
| 38 | + var encoded = |
| 39 | + r"$2b$04$eH8zX.q5Q.j2hO1NkVYJQOM6KxntS/ow3.YzVmFrE4t//CoF4fvne"; |
| 40 | + var output = bcrypt(utf8.encode(password), encoded); |
| 41 | + expect(output, equals(encoded)); |
| 42 | + }); |
| 43 | + |
| 44 | + test(r"$2b$04$ahiTdwRXpUG2JLRcIznxc.s1.ydaPGD372bsGs8NqyYjLY1inG5n2", () { |
| 45 | + var password = "Tg4daC27epFBE"; |
| 46 | + var encoded = |
| 47 | + r"$2b$04$ahiTdwRXpUG2JLRcIznxc.s1.ydaPGD372bsGs8NqyYjLY1inG5n2"; |
| 48 | + var output = bcrypt(utf8.encode(password), encoded); |
| 49 | + expect(output, equals(encoded)); |
| 50 | + }); |
| 51 | + |
| 52 | + test(r"$2b$04$nQn78dV0hGHf5wUBe0zOFu8n07ZbWWOKoGasZKRspZxtt.vBRNMIy", () { |
| 53 | + var password = "xhQPMmwh5ALzW"; |
| 54 | + var encoded = |
| 55 | + r"$2b$04$nQn78dV0hGHf5wUBe0zOFu8n07ZbWWOKoGasZKRspZxtt.vBRNMIy"; |
| 56 | + var output = bcrypt(utf8.encode(password), encoded); |
| 57 | + expect(output, equals(encoded)); |
| 58 | + }); |
| 59 | + |
| 60 | + test(r"$2b$04$cvXudZ5ugTg95W.rOjMITuM1jC0piCl3zF5cmGhzCibHZrNHkmckG", () { |
| 61 | + var password = "59je8h5Gj71tg"; |
| 62 | + var encoded = |
| 63 | + r"$2b$04$cvXudZ5ugTg95W.rOjMITuM1jC0piCl3zF5cmGhzCibHZrNHkmckG"; |
| 64 | + var output = bcrypt(utf8.encode(password), encoded); |
| 65 | + expect(output, equals(encoded)); |
| 66 | + }); |
| 67 | + |
| 68 | + test(r"$2b$04$YYjtiq4Uh88yUsExO0RNTuEJ.tZlsONac16A8OcLHleWFjVawfGvO", () { |
| 69 | + var password = "wT4fHJa2N9WSW"; |
| 70 | + var encoded = |
| 71 | + r"$2b$04$YYjtiq4Uh88yUsExO0RNTuEJ.tZlsONac16A8OcLHleWFjVawfGvO"; |
| 72 | + var output = bcrypt(utf8.encode(password), encoded); |
| 73 | + expect(output, equals(encoded)); |
| 74 | + }); |
| 75 | + |
| 76 | + test(r"$2b$04$WLTjgY/pZSyqX/fbMbJzf.qxCeTMQOzgL.CimRjMHtMxd/VGKojMu", () { |
| 77 | + var password = "uSgFRnQdOgm4S"; |
| 78 | + var encoded = |
| 79 | + r"$2b$04$WLTjgY/pZSyqX/fbMbJzf.qxCeTMQOzgL.CimRjMHtMxd/VGKojMu"; |
| 80 | + var output = bcrypt(utf8.encode(password), encoded); |
| 81 | + expect(output, equals(encoded)); |
| 82 | + }); |
| 83 | + |
| 84 | + test(r"$2b$04$2moPs/x/wnCfeQ5pCheMcuSJQ/KYjOZG780UjA/SiR.KsYWNrC7SG", () { |
| 85 | + var password = "tEPtJZXur16Vg"; |
| 86 | + var encoded = |
| 87 | + r"$2b$04$2moPs/x/wnCfeQ5pCheMcuSJQ/KYjOZG780UjA/SiR.KsYWNrC7SG"; |
| 88 | + var output = bcrypt(utf8.encode(password), encoded); |
| 89 | + expect(output, equals(encoded)); |
| 90 | + }); |
| 91 | + |
| 92 | + test(r"$2b$04$HrEYC/AQ2HS77G78cQDZQ.r44WGcruKw03KHlnp71yVQEwpsi3xl2", () { |
| 93 | + var password = "vvho8C6nlVf9K"; |
| 94 | + var encoded = |
| 95 | + r"$2b$04$HrEYC/AQ2HS77G78cQDZQ.r44WGcruKw03KHlnp71yVQEwpsi3xl2"; |
| 96 | + var output = bcrypt(utf8.encode(password), encoded); |
| 97 | + expect(output, equals(encoded)); |
| 98 | + }); |
| 99 | + |
| 100 | + test(r"$2b$04$vVYgSTfB8KVbmhbZE/k3R.ux9A0lJUM4CZwCkHI9fifke2.rTF7MG", () { |
| 101 | + var password = "5auCCY9by0Ruf"; |
| 102 | + var encoded = |
| 103 | + r"$2b$04$vVYgSTfB8KVbmhbZE/k3R.ux9A0lJUM4CZwCkHI9fifke2.rTF7MG"; |
| 104 | + var output = bcrypt(utf8.encode(password), encoded); |
| 105 | + expect(output, equals(encoded)); |
| 106 | + }); |
| 107 | + |
| 108 | + test(r"$2b$04$JfoNrR8.doieoI8..F.C1OQgwE3uTeuardy6lw0AjALUzOARoyf2m", () { |
| 109 | + var password = "GtTkR6qn2QOZW"; |
| 110 | + var encoded = |
| 111 | + r"$2b$04$JfoNrR8.doieoI8..F.C1OQgwE3uTeuardy6lw0AjALUzOARoyf2m"; |
| 112 | + var output = bcrypt(utf8.encode(password), encoded); |
| 113 | + expect(output, equals(encoded)); |
| 114 | + }); |
| 115 | + |
| 116 | + test(r"$2b$04$HP3I0PUs7KBEzMBNFw7o3O7f/uxaZU7aaDot1quHMgB2yrwBXsgyy", () { |
| 117 | + var password = "zKo8vdFSnjX0f"; |
| 118 | + var encoded = |
| 119 | + r"$2b$04$HP3I0PUs7KBEzMBNFw7o3O7f/uxaZU7aaDot1quHMgB2yrwBXsgyy"; |
| 120 | + var output = bcrypt(utf8.encode(password), encoded); |
| 121 | + expect(output, equals(encoded)); |
| 122 | + }); |
| 123 | + |
| 124 | + test(r"$2b$04$xnFVhJsTzsFBTeP3PpgbMeMREb6rdKV9faW54Sx.yg9plf4jY8qT6", () { |
| 125 | + var password = "I9VfYlacJiwiK"; |
| 126 | + var encoded = |
| 127 | + r"$2b$04$xnFVhJsTzsFBTeP3PpgbMeMREb6rdKV9faW54Sx.yg9plf4jY8qT6"; |
| 128 | + var output = bcrypt(utf8.encode(password), encoded); |
| 129 | + expect(output, equals(encoded)); |
| 130 | + }); |
| 131 | + |
| 132 | + test(r"$2b$04$WQp9.igoLqVr6Qk70mz6xuRxE0RttVXXdukpR9N54x17ecad34ZF6", () { |
| 133 | + var password = "VFPO7YXnHQbQO"; |
| 134 | + var encoded = |
| 135 | + r"$2b$04$WQp9.igoLqVr6Qk70mz6xuRxE0RttVXXdukpR9N54x17ecad34ZF6"; |
| 136 | + var output = bcrypt(utf8.encode(password), encoded); |
| 137 | + expect(output, equals(encoded)); |
| 138 | + }); |
| 139 | + |
| 140 | + test(r"$2b$04$xgZtlonpAHSU/njOCdKztOPuPFzCNVpB4LGicO4/OGgHv.uKHkwsS", () { |
| 141 | + var password = "VDx5BdxfxstYk"; |
| 142 | + var encoded = |
| 143 | + r"$2b$04$xgZtlonpAHSU/njOCdKztOPuPFzCNVpB4LGicO4/OGgHv.uKHkwsS"; |
| 144 | + var output = bcrypt(utf8.encode(password), encoded); |
| 145 | + expect(output, equals(encoded)); |
| 146 | + }); |
| 147 | + |
| 148 | + test(r"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe", () { |
| 149 | + var password = "dEe6XfVGrrfSH"; |
| 150 | + var encoded = |
| 151 | + r"$2b$04$2Siw3Nv3Q/gTOIPetAyPr.GNj3aO0lb1E5E9UumYGKjP9BYqlNWJe"; |
| 152 | + var output = bcrypt(utf8.encode(password), encoded); |
| 153 | + expect(output, equals(encoded)); |
| 154 | + }); |
| 155 | + |
| 156 | + test(r"$2b$04$7/Qj7Kd8BcSahPO4khB8me4ssDJCW3r4OGYqPF87jxtrSyPj5cS5m", () { |
| 157 | + var password = "cTT0EAFdwJiLn"; |
| 158 | + var encoded = |
| 159 | + r"$2b$04$7/Qj7Kd8BcSahPO4khB8me4ssDJCW3r4OGYqPF87jxtrSyPj5cS5m"; |
| 160 | + var output = bcrypt(utf8.encode(password), encoded); |
| 161 | + expect(output, equals(encoded)); |
| 162 | + }); |
| 163 | + |
| 164 | + test(r"$2b$04$VvlCUKbTMjaxaYJ.k5juoecpG/7IzcH1AkmqKi.lIZMVIOLClWAk.", () { |
| 165 | + var password = "J8eHUDuxBB520"; |
| 166 | + var encoded = |
| 167 | + r"$2b$04$VvlCUKbTMjaxaYJ.k5juoecpG/7IzcH1AkmqKi.lIZMVIOLClWAk."; |
| 168 | + var output = bcrypt(utf8.encode(password), encoded); |
| 169 | + expect(output, equals(encoded)); |
| 170 | + }); |
| 171 | + |
| 172 | + test(r"$2b$10$keO.ZZs22YtygVF6BLfhGOI/JjshJYPp8DZsUtym6mJV2Eha2Hdd.", () { |
| 173 | + var password = [ |
| 174 | + 125, 62, 179, 254, 241, 139, 160, 230, 40, 162, 76, 122, 113, 195, // |
| 175 | + 80, 127, 204, 200, 98, 123, 249, 20, 246, 246, 96, 129, 71, 53, 236, |
| 176 | + 29, 135, 16, 191, 167, 225, 125, 73, 55, 32, 150, 223, 99, 242, 191, |
| 177 | + 179, 86, 104, 223, 77, 136, 113, 247, 255, 27, 130, 126, 122, 19, 221, |
| 178 | + 233, 132, 0, 221, 52 |
| 179 | + ]; |
| 180 | + var encoded = |
| 181 | + r"$2b$10$keO.ZZs22YtygVF6BLfhGOI/JjshJYPp8DZsUtym6mJV2Eha2Hdd."; |
| 182 | + var output = bcrypt(password, encoded); |
| 183 | + expect(output, equals(encoded)); |
| 184 | + }); |
| 185 | + }); |
| 186 | +} |
0 commit comments