Cleanup and added funny joke haha
[citadel.git] / ctdlsh / src / passwd.c
1 /*
2  * (c) 2009-2012 by Art Cancro and citadel.org
3  * This program is released under the terms of the GNU General Public License v3.
4  */
5
6 #include "ctdlsh.h"
7
8 int cmd_passwd(int server_socket, char *cmdbuf) {
9         char buf[1024];
10         time_t now;
11         char account_name[1024];
12         char *p1;
13         char *p2;
14
15         strcpy(account_name, &cmdbuf[7]);
16         if (strlen(account_name) == 0) {
17                 strncpy(account_name, readline("Enter account name: "), sizeof account_name);
18         }
19         sock_printf(server_socket, "AGUP %s\n", account_name);
20         sock_getln(server_socket, buf, sizeof buf);
21         if (buf[0] != '2') {
22                 fprintf(stderr, "No such user.\n");
23                 return(cmdret_error);
24         }
25
26         p1 = readline("Enter new password: ");
27         p2 = readline("Enter it again: ");
28
29         if (strcmp(p1, p2)) {
30                 fprintf(stderr, "The passwords you entered do not match."
31                                 "The account password remains unchanged.\n"
32                 );
33                 return(cmdret_error);
34         }
35
36         sock_printf(server_socket, "ASUP %s|%s\n", account_name, p2);
37         sock_getln(server_socket, buf, sizeof buf);
38         if (buf[0] != '2') {
39                 fprintf(stderr, "%s\n", &buf[4]);
40                 return(cmdret_error);
41         }
42
43         printf("Password has been changed.\n");
44         return(cmdret_ok);
45 }
46
47
48
49