aboutsummaryrefslogtreecommitdiff
path: root/src/storage/user.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/user.zig')
-rw-r--r--src/storage/user.zig24
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();