]>
Commit | Line | Data |
---|---|---|
1dd6d55d | 1 | /* Automatically generated by refactor.pl. |
2 | * | |
3 | * | |
4 | * CMDNAME: newpass | |
5 | * CMDLEVEL: QCMD_AUTHED | |
6 | * CMDARGS: 3 | |
7 | * CMDDESC: Change your password. | |
8 | * CMDFUNC: csa_donewpw | |
9 | * CMDPROTO: int csa_donewpw(void *source, int cargc, char **cargv); | |
10 | */ | |
11 | ||
12 | #include "../chanserv.h" | |
13 | #include "../authlib.h" | |
14 | #include "../../lib/irc_string.h" | |
15 | #include <stdio.h> | |
16 | #include <string.h> | |
80d2de64 | 17 | #include <ctype.h> |
1dd6d55d | 18 | |
19 | int csa_donewpw(void *source, int cargc, char **cargv) { | |
20 | reguser *rup; | |
21 | nick *sender=source; | |
80d2de64 | 22 | int i, cntweak = 0, cntdigits = 0, cntletters = 0; |
1dd6d55d | 23 | |
24 | if (cargc<3) { | |
25 | chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "newpass"); | |
26 | return CMD_ERROR; | |
27 | } | |
28 | ||
29 | if (!(rup=getreguserfromnick(sender))) | |
30 | return CMD_ERROR; | |
31 | ||
32 | if (!checkmasterpassword(rup, cargv[0])) { | |
33 | chanservstdmessage(sender, QM_AUTHFAIL); | |
34 | cs_log(sender,"NEWPASS FAIL username %s bad masterpassword %s",rup->username,cargv[0]); | |
35 | return CMD_ERROR; | |
36 | } | |
37 | ||
38 | if (strcmp(cargv[1],cargv[2])) { | |
39 | chanservstdmessage(sender, QM_PWDONTMATCH); /* Sorry, passwords do not match */ | |
40 | cs_log(sender,"NEWPASS FAIL username %s new passwords don't match (%s vs %s)",rup->username,cargv[1],cargv[2]); | |
41 | return CMD_ERROR; | |
42 | } | |
43 | ||
44 | if (strlen(cargv[1]) < 6) { | |
45 | chanservstdmessage(sender, QM_PWTOSHORT); /* new password to short */ | |
46 | cs_log(sender,"NEWPASS FAIL username %s password to short %s (%d characters)",rup->username,cargv[1],strlen(cargv[1])); | |
47 | return CMD_ERROR; | |
48 | } | |
49 | ||
cb7fb82d P |
50 | for ( i = 0; cargv[1][i] && i < PASSLEN; i++ ) { |
51 | if ( cargv[1][i] == cargv[1][i+1] || cargv[1][i] + 1 == cargv[1][i+1] || cargv[1][i] - 1 == cargv[1][i+1] ) | |
52 | cntweak++; | |
53 | if(isdigit(cargv[1][i])) | |
54 | cntdigits++; | |
55 | if(islower(cargv[1][i]) || isupper(cargv[1][i])) | |
56 | cntletters++; | |
57 | } | |
58 | ||
59 | if( cntweak > 3 || !cntdigits || !cntletters) { | |
60 | chanservstdmessage(sender, QM_PWTOWEAK); /* new password is weak */ | |
61 | cs_log(sender,"NEWPASS FAIL username %s password to weak %s",rup->username,cargv[1]); | |
62 | return CMD_ERROR; | |
63 | } | |
64 | ||
1dd6d55d | 65 | setpassword(rup, cargv[1]); |
66 | rup->lastauth=time(NULL); | |
67 | chanservstdmessage(sender, QM_PWCHANGED); | |
68 | cs_log(sender,"NEWPASS OK username %s", rup->username); | |
69 | csdb_updateuser(rup); | |
70 | csdb_createmail(rup, QMAIL_NEWPW); | |
71 | ||
72 | return CMD_OK; | |
73 | } |