X-Git-Url: https://gitweb.ps.run/chirp/blobdiff_plain/c2ae0de6287635110bbcf3478c3d8935d38d02c6..d3f75db179e5509a290f0b010027c48bc86958b7:/src/main.zig
diff --git a/src/main.zig b/src/main.zig
index 29bedcf..d2622b9 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -163,19 +163,18 @@ fn decode(text: []const u8) !std.BoundedArray(u8, 1024) {
const Chirp = struct {
const PostsPerPage = 10;
const UsersPerPage = 10;
+ var HashBuffer = std.mem.zeroes([1024 * 1024 * 50]u8);
pub fn hash_password(password: []const u8) !PasswordHash {
var hash_buffer = try PasswordHash.init(128);
// TODO: choose buffer size
- // TODO: dont allocate on stack, maybe zero memory?
- var buffer: [1024 * 10]u8 = undefined;
- var alloc = std.heap.FixedBufferAllocator.init(&buffer);
+ var alloc = std.heap.FixedBufferAllocator.init(&HashBuffer);
// TODO: choose limits
const result = try std.crypto.pwhash.argon2.strHash(password, .{
.allocator = alloc.allocator(),
- .params = std.crypto.pwhash.argon2.Params.fromLimits(1000, 1024),
+ .params = std.crypto.pwhash.argon2.Params.owasp_2id,
}, hash_buffer.slice());
try hash_buffer.resize(result.len);
@@ -184,8 +183,7 @@ const Chirp = struct {
}
pub fn verify_password(password: []const u8, hash: PasswordHash) bool {
- var buffer: [1024 * 10]u8 = undefined;
- var alloc = std.heap.FixedBufferAllocator.init(&buffer);
+ var alloc = std.heap.FixedBufferAllocator.init(&HashBuffer);
if (std.crypto.pwhash.argon2.strVerify(hash.constSlice(), password, .{
.allocator = alloc.allocator(),
@@ -716,7 +714,7 @@ fn write_post(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_id: Po
try res.write("
", .{});
try html_form(res, "/comment", .{
.{ "type=\"hidden\" value=\"{x}\" name=\"post_id\"", .{@intFromEnum(post.id)} },
- "type=\"text\" name=\"text\" placeholder=\"Text\"",
+ .{ "textarea", "type=\"text\" name=\"text\" placeholder=\"Text\"", .{} },
"type=\"submit\" value=\"Comment\"",
});
try res.write("
", .{});
@@ -858,6 +856,10 @@ fn write_timeline(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user_li
var prev_newest_post: ?Post = null;
const following = try user_list.open(txn);
+ if (following.len() == 0) {
+ try res.write("Empty timeline (no users)", .{});
+ return;
+ }
while (true) {
var newest_post: ?Post = null;
@@ -1164,7 +1166,7 @@ const GET = struct {
try html_form(self.res, "/quote", .{
.{ "type=\"hidden\" name=\"referer\" value=\"{s}\"", .{referer} },
.{ "type=\"hidden\" name=\"post_id\" value=\"{x}\"", .{@intFromEnum(post.id)} },
- "type=\"text\" name=\"text\" placeholder=\"Text\" autofocus",
+ .{ "textarea", "type=\"text\" name=\"text\" placeholder=\"Text\" autofocus", .{} },
"type=\"submit\" value=\"Quote\"",
});
try self.res.write("
", .{});
@@ -1250,7 +1252,7 @@ const GET = struct {
try html_form(self.res, "/post", .{
.{ "type=\"hidden\" name=\"referer\" value=\"{s}\"", .{referer} },
- "type=\"text\" name=\"text\" placeholder=\"Text\" autofocus",
+ .{ "textarea", "type=\"text\" name=\"text\" placeholder=\"Text\" autofocus", .{} },
"type=\"submit\" value=\"Post\"",
});
} else {