Grammar change in the license declaration.
[citadel.git] / citadel / server / makeuserkey.c
1 // makeuserkey() - convert a username into the format used as a database key
2 //
3 // Copyright (c) 1987-2024 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to 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 <string.h>
15 #include "config.h"
16 #include "user_ops.h"
17
18
19 // makeuserkey() - convert a username into the format used as a database key
20 //              "key" must be a buffer of at least USERNAME_SIZE
21 //              (Key format is the username with all non-alphanumeric characters removed, and converted to lower case.)
22 void makeuserkey(char *key, const char *username) {
23         int i;
24         int keylen = 0;
25
26         if (IsEmptyStr(username)) {
27                 key[0] = 0;
28                 return;
29         }
30
31         int len = strlen(username);
32         for (i=0; ((i<=len) && (i<USERNAME_SIZE-1)); ++i) {
33                 if (isalnum((username[i]))) {
34                         key[keylen++] = tolower(username[i]);
35                 }
36         }
37         key[keylen++] = 0;
38 }