From 25228df6d13b5e8541672c4cdd84e200ff56a4c4 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 19 Nov 2025 18:58:54 +0100 Subject: add profile settings to backend and add image loader --- src/storage/user.zig | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'src/storage') 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(); -- cgit v1.2.3-70-g09d2