5729034a504c0ed423951c03b12cae5fc8004f3b
[citadel.git] / citadel / server / makeuserkey.c
1 // makeuserkey() - convert a username into the format used as a database key
2 //
3 // Copyright (c) 1987-2023 by the citadel.org team
4 //
5 // This program is open source software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License, version 3.
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include "sysdep.h"
11 #include <stdio.h>
12 #include <sys/stat.h>
13 #include <libcitadel.h>
14 #include "config.h"
15 #include "user_ops.h"
16
17
18 // makeuserkey() - convert a username into the format used as a database key
19 //              "key" must be a buffer of at least USERNAME_SIZE
20 //              (Key format is the username with all non-alphanumeric characters removed, and converted to lower case.)
21 void makeuserkey(char *key, const char *username) {
22         int i;
23         int keylen = 0;
24
25         if (IsEmptyStr(username)) {
26                 key[0] = 0;
27                 return;
28         }
29
30         int len = strlen(username);
31         for (i=0; ((i<=len) && (i<USERNAME_SIZE-1)); ++i) {
32                 if (isalnum((username[i]))) {
33                         key[keylen++] = tolower(username[i]);
34                 }
35         }
36         key[keylen++] = 0;
37 }
38
39