diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-19 18:58:54 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-19 18:58:54 +0100 |
| commit | 25228df6d13b5e8541672c4cdd84e200ff56a4c4 (patch) | |
| tree | 924cc6bdc00440c6bf592b04602261cdab17d60a /src/storage | |
| parent | 4c06eb64cbed3562e428ce59857d1763098638f3 (diff) | |
add profile settings to backend and add image loader
Diffstat (limited to 'src/storage')
| -rw-r--r-- | src/storage/user.zig | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/storage/user.zig b/src/storage/user.zig index 09f7716..86d82ff 100644 --- a/src/storage/user.zig +++ b/src/storage/user.zig @@ -48,9 +48,8 @@ arena: std.heap.ArenaAllocator, pub fn open( storage: *Storage, name: []const u8, - inner_allocator: std.mem.Allocator ) !Self { - var arena: std.heap.ArenaAllocator = .init(inner_allocator); + var arena: std.heap.ArenaAllocator = .init(storage.allocator); errdefer arena.deinit(); const allocator = arena.allocator(); @@ -125,9 +124,26 @@ pub fn new( }; } +pub fn set_password(self: *Self, password: []const u8) !void { + const allocator = self.area.allocator(); + const hash_buf = try allocator.alloc(u8, 256); + const hash = try std.crypto.pwhash.bcrypt.strHash( + password, + .{ + .params = .{ + .rounds_log = 3, + .silently_truncate_password = false, + }, + .encoding = .phc, + }, + hash_buf + ); + + self.info.hash = hash; +} + pub fn sync(self: *Self) !void { - const file = try self.dir.openFile("info.json", .{ - .mode = .write_only, + const file = try self.dir.createFile("info.json", .{ .lock = .exclusive, }); defer file.close(); |