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);
}
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(),
\\ form {
\\ display: inline-block;
\\ }
+ \\ body {
+ \\ margin:40px auto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:0 10px;
+ \\ }
+ \\ h1,h2,h3{line-height:1.2}
\\</style>
\\</head>
\\<body>
try res.write("<br /><br />", .{});
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("<br />", .{});
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;
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("<br />", .{});
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 {