AmendHub

Download

jcs

/

subtext

/

user.h

 

(View History)

jcs   user: Add user_first_sysop_id() Latest amendment: 562 on 2023-11-27

1 /*
2 * Copyright (c) 2021 joshua stein <jcs@jcs.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef __USER_H__
18 #define __USER_H__
19
20 #include "sha2.h"
21
22 #define AUTH_USER_OK 1
23 #define AUTH_USER_FAILED 2
24 #define AUTH_USER_GUEST 3
25 #define AUTH_USER_SIGNUP 4
26
27 #define GUEST_USERNAME "guest"
28
29 struct user {
30 unsigned long id;
31 char username[DB_USERNAME_LENGTH + 1];
32 char password_hash[SHA256_DIGEST_STRING_LENGTH + 1]; /* 66 */
33 char password_salt[SHA256_DIGEST_STRING_LENGTH + 1];
34 unsigned long created_at;
35 unsigned long last_seen_at;
36 short is_sysop;
37 short is_enabled;
38 unsigned long last_motd_seen;
39 };
40
41 struct username_cache {
42 unsigned long id;
43 char username[DB_USERNAME_LENGTH + 1];
44 };
45
46 void user_cache_usernames(void);
47 bool user_save(struct user *user);
48 struct user * user_find(unsigned long id);
49 struct user * user_find_by_username(const char *username);
50 struct username_cache * user_username(unsigned long id);
51 short user_authenticate(struct user *user, const char *password);
52 bool user_set_password(struct user *user, const char *password);
53 bool user_valid_username(struct user *user, char *username, char **error);
54 bool user_username_is_banned(char *username);
55 unsigned long user_first_sysop_id(void);
56 void user_change_password(struct session *s, struct user *user);
57 void user_delete(struct user *user);
58
59 #endif