summaryrefslogtreecommitdiff
path: root/snac.c
diff options
context:
space:
mode:
authorGravatar default2022-09-19 22:58:27 +0200
committerGravatar default2022-09-19 22:58:27 +0200
commit8be433c9b65fe5f214151651055700d1fea02a56 (patch)
treef10a87901d7b2fdaab66951501b0d8dfada33e00 /snac.c
parent[data.c] new file. (diff)
downloadsnac2-8be433c9b65fe5f214151651055700d1fea02a56.tar.gz
snac2-8be433c9b65fe5f214151651055700d1fea02a56.tar.xz
snac2-8be433c9b65fe5f214151651055700d1fea02a56.zip
New function hash_password() and check_password().
Diffstat (limited to 'snac.c')
-rw-r--r--snac.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/snac.c b/snac.c
index 0238b7a..dd76e06 100644
--- a/snac.c
+++ b/snac.c
@@ -90,3 +90,36 @@ void snac_debug(snac *snac, int level, d_char *str)
90 fprintf(stderr, "%s [%s] %s\n", tm, snac->uid, msg); 90 fprintf(stderr, "%s [%s] %s\n", tm, snac->uid, msg);
91 } 91 }
92} 92}
93
94
95d_char *hash_password(char *uid, char *passwd, char *nonce)
96/* hashes a password */
97{
98 xs *d_nonce = NULL;
99 xs *combi;
100 xs *hash;
101
102 if (nonce == NULL)
103 nonce = d_nonce = xs_fmt("%08x", random());
104
105 combi = xs_fmt("%s:%s:%s", nonce, uid, passwd);
106 hash = xs_sha1_hex(combi, strlen(combi));
107
108 return xs_fmt("%s:%s", nonce, hash);
109}
110
111
112int check_password(char *uid, char *passwd, char *hash)
113/* checks a password */
114{
115 int ret = 0;
116 xs *spl = xs_splitn(hash, ":", 1);
117
118 if (xs_list_len(spl) == 2) {
119 xs *n_hash = hash_password(uid, passwd, xs_list_get(spl, 0));
120
121 ret = (strcmp(hash, n_hash) == 0);
122 }
123
124 return ret;
125}