From b3b15cec292d3671897afdb7ff549dae66735647 Mon Sep 17 00:00:00 2001 From: default Date: Wed, 28 Sep 2022 05:36:35 +0200 Subject: [PATCH] New function login() (untested). --- html.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/html.c b/html.c index 0a070b2..8745c8b 100644 --- a/html.c +++ b/html.c @@ -3,6 +3,7 @@ #include "xs.h" #include "xs_io.h" +#include "xs_encdec.h" #include "xs_json.h" #include "xs_regex.h" @@ -118,6 +119,29 @@ d_char *not_really_markdown(char *content, d_char **f_content) } +int login(snac *snac, char *headers) +/* tries a login */ +{ + int logged_in = 0; + char *auth = xs_dict_get(headers, "authorization"); + + if (auth && xs_startswith(auth, "Basic ")) { + int sz; + xs *s1 = xs_crop(xs_dup(auth), 6, 0); + xs *s2 = xs_base64_dec(s1, &sz); + xs *l1 = xs_split_n(s2, ":", 1); + + if (xs_list_len(l1) == 2) { + logged_in = check_password( + xs_list_get(l1, 0), xs_list_get(l1, 1), + xs_dict_get(snac->config, "passwd")); + } + } + + return logged_in; +} + + int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) { int status = 0;