summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-12-04 21:14:18 +0100
committerdefault <nobody@localhost>2022-12-04 21:14:18 +0100
commit7787a2ded9a0ab445c9bd310dfc8b909509d763f (patch)
treec1e61ed69f68cf22cd74a45c8133f98b61a4cfbe /utils.c
parent67140840112c1c791503435ece16654d50ba8929 (diff)
New function new_password().
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/utils.c b/utils.c
index 8b0b458..300115b 100644
--- a/utils.c
+++ b/utils.c
@@ -187,13 +187,27 @@ int initdb(const char *basedir)
}
-int adduser(char *uid)
+void new_password(const char *uid, d_char **clear_pwd, d_char **hashed_pwd)
+/* creates a random password */
+{
+ int rndbuf[3];
+
+ srandom(time(NULL) ^ getpid());
+ rndbuf[0] = random() & 0xffffffff;
+ rndbuf[1] = random() & 0xffffffff;
+ rndbuf[2] = random() & 0xffffffff;
+
+ *clear_pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf));
+ *hashed_pwd = hash_password(uid, *clear_pwd, NULL);
+}
+
+
+int adduser(const char *uid)
/* creates a new user */
{
snac snac;
xs *config = xs_dict_new();
xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
- int rndbuf[3];
xs *pwd = NULL;
xs *pwd_f = NULL;
xs *key = NULL;
@@ -214,13 +228,7 @@ int adduser(char *uid)
return 1;
}
- srandom(time(NULL) ^ getpid());
- rndbuf[0] = random() & 0xffffffff;
- rndbuf[1] = random() & 0xffffffff;
- rndbuf[2] = random() & 0xffffffff;
-
- pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf));
- pwd_f = hash_password(uid, pwd, NULL);
+ new_password(uid, &pwd, &pwd_f);
config = xs_dict_append(config, "uid", uid);
config = xs_dict_append(config, "name", uid);