Add password change API
[blerg.git] / cgi / cgi_blerg.c
index 4d55411..7e5c7df 100644 (file)
@@ -413,6 +413,23 @@ int main(int argc, char *argv[]) {
                fwrite(ybuf, len, 1, stdout);
 
                yajl_gen_free(g);
+       } else if (strncmp(path, "/passwd", 7) == 0) {
+               const char *username = cgi_getentrystr("username");
+               if (!check_auth(username))
+                       exit(0);
+
+               const char *password = cgi_getentrystr("password");
+               const char *new_password = cgi_getentrystr("new_password");
+               if (password == NULL || new_password == NULL) {
+                       respond_JSON_Failure();
+               } else {
+                       if (auth_check_password(username, password)) {
+                               auth_set_password(username, new_password);
+                               respond_JSON_Success();
+                       } else {
+                               respond_JSON_Failure();
+                       }
+               }
        } else {
                respond_404();
                exit(0);