╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../event.zig"); 3 const xit = @import("xit"); 4 const hash = xit.hash; 5 const bcrypt = std.crypto.pwhash.bcrypt; 6 7 name: []const u8, 8 email: []const u8, 9 password_hash: []const u8, 10 11 pub fn read( 12 comptime DB: type, 13 comptime hash_kind: hash.HashKind, 14 arena: *std.heap.ArenaAllocator, 15 map: DB.HashMap(.read_only), 16 ) !@This() { 17 return .{ 18 .name = try evt.readBytes(DB, hash_kind, arena.allocator(), map, "name"), 19 .email = try evt.readBytes(DB, hash_kind, arena.allocator(), map, "email"), 20 .password_hash = try evt.readBytes(DB, hash_kind, arena.allocator(), map, "password_hash"), 21 }; 22 } 23 24 pub const password_hash_max_len = bcrypt.hash_length * 2; 25 26 pub fn hashPassword( 27 password: []const u8, 28 out: []u8, 29 io: std.Io, 30 ) ![]const u8 { 31 return bcrypt.strHash(password, .{ 32 .params = bcrypt.Params.owasp, 33 .encoding = .phc, 34 }, out, io); 35 } 36