diff options
| author | 2022-12-04 21:14:18 +0100 | |
|---|---|---|
| committer | 2022-12-04 21:14:18 +0100 | |
| commit | 7787a2ded9a0ab445c9bd310dfc8b909509d763f (patch) | |
| tree | c1e61ed69f68cf22cd74a45c8133f98b61a4cfbe /utils.c | |
| parent | Merge branch 'master' of triptico.com:git/snac2 (diff) | |
| download | snac2-7787a2ded9a0ab445c9bd310dfc8b909509d763f.tar.gz snac2-7787a2ded9a0ab445c9bd310dfc8b909509d763f.tar.xz snac2-7787a2ded9a0ab445c9bd310dfc8b909509d763f.zip | |
New function new_password().
Diffstat (limited to 'utils.c')
| -rw-r--r-- | utils.c | 26 |
1 files changed, 17 insertions, 9 deletions
| @@ -187,13 +187,27 @@ int initdb(const char *basedir) | |||
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | 189 | ||
| 190 | int adduser(char *uid) | 190 | void new_password(const char *uid, d_char **clear_pwd, d_char **hashed_pwd) |
| 191 | /* creates a random password */ | ||
| 192 | { | ||
| 193 | int rndbuf[3]; | ||
| 194 | |||
| 195 | srandom(time(NULL) ^ getpid()); | ||
| 196 | rndbuf[0] = random() & 0xffffffff; | ||
| 197 | rndbuf[1] = random() & 0xffffffff; | ||
| 198 | rndbuf[2] = random() & 0xffffffff; | ||
| 199 | |||
| 200 | *clear_pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf)); | ||
| 201 | *hashed_pwd = hash_password(uid, *clear_pwd, NULL); | ||
| 202 | } | ||
| 203 | |||
| 204 | |||
| 205 | int adduser(const char *uid) | ||
| 191 | /* creates a new user */ | 206 | /* creates a new user */ |
| 192 | { | 207 | { |
| 193 | snac snac; | 208 | snac snac; |
| 194 | xs *config = xs_dict_new(); | 209 | xs *config = xs_dict_new(); |
| 195 | xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); | 210 | xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); |
| 196 | int rndbuf[3]; | ||
| 197 | xs *pwd = NULL; | 211 | xs *pwd = NULL; |
| 198 | xs *pwd_f = NULL; | 212 | xs *pwd_f = NULL; |
| 199 | xs *key = NULL; | 213 | xs *key = NULL; |
| @@ -214,13 +228,7 @@ int adduser(char *uid) | |||
| 214 | return 1; | 228 | return 1; |
| 215 | } | 229 | } |
| 216 | 230 | ||
| 217 | srandom(time(NULL) ^ getpid()); | 231 | new_password(uid, &pwd, &pwd_f); |
| 218 | rndbuf[0] = random() & 0xffffffff; | ||
| 219 | rndbuf[1] = random() & 0xffffffff; | ||
| 220 | rndbuf[2] = random() & 0xffffffff; | ||
| 221 | |||
| 222 | pwd = xs_base64_enc((char *)rndbuf, sizeof(rndbuf)); | ||
| 223 | pwd_f = hash_password(uid, pwd, NULL); | ||
| 224 | 232 | ||
| 225 | config = xs_dict_append(config, "uid", uid); | 233 | config = xs_dict_append(config, "uid", uid); |
| 226 | config = xs_dict_append(config, "name", uid); | 234 | config = xs_dict_append(config, "name", uid); |