New function login() (untested).

This commit is contained in:
default 2022-09-28 05:36:35 +02:00
parent b2c8264003
commit b3b15cec29

24
html.c
View file

@ -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;