hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

+test.ha (689B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use fmt;
      5 use strings;
      6 
      7 @test fn bcrypt() void = {
      8 	const pass = strings::toutf8("hare is cool");
      9 	const hash = generate(pass, DEFAULT_COST);
     10 	defer free(hash);
     11 	assert(compare(hash, pass)!);
     12 	const notpass = strings::toutf8("hare is lame");
     13 	assert(!compare(hash, notpass)!);
     14 };
     15 
     16 @test fn hash() void = {
     17 	const pass = strings::toutf8("allmine");
     18 	const salt = strings::toutf8("XajjQvNhvvRt5GSeFk1xFe");
     19 	const expect = "$2a$10$XajjQvNhvvRt5GSeFk1xFeyqRrsxkhBkUiQeg0dt.wU1qD4aFDcga";
     20 
     21 	const hash = strings::fromutf8(bcrypt(pass, salt, 10)!)!;
     22 	defer free(hash);
     23 	assert(strings::hassuffix(expect, hash));
     24 };