Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace requestpassword with lostpassword #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions chanserv/authcmds/lostpassword.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* CMDNAME: lostpassword
* CMDALIASES: lostpass
* CMDLEVEL: QCMD_NOTAUTHED
* CMDARGS: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

* CMDDESC: Sends a code to reset the password with.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sends instructions for resetting your account to your registered email address.

* CMDFUNC: csa_dolostpw
* CMDPROTO: int csa_dolostpw(void *source, int cargc, char **cargv);
* CMDHELP: Usage: @UCOMMAND@ <email>
* CMDHELP: Sends instructions for resetting your account to your registered email address, where:
* CMDHELP: email - your email address
*/

#include "../chanserv.h"
#include "../authlib.h"
#include "../../lib/irc_string.h"
#include <stdio.h>
#include <string.h>

int csa_dolostpw(void *source, int cargc, char **cargv) {
reguser *rup;
nick *sender=source;
time_t t;
int i, matched = 0;

if (cargc<1) {
chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "lostpassword");
return CMD_ERROR;
}

t=time(NULL);

for (i=0;i<REGUSERHASHSIZE;i++) {
for (rup=regusernicktable[i];rup;rup=rup->nextbyname) {
if(!rup->email || strcasecmp(cargv[0],rup->email->content))
continue;

if(UHasStaffPriv(rup)) {
cs_log(sender,"LOSTPASSWORD FAIL privileged email %s",cargv[0]);
continue;
}

matched = 1;

if(rup->lockuntil && rup->lockuntil > t) {
chanservstdmessage(sender, QM_ACCOUNTLOCKED, rup->lockuntil);
continue;
}

if(csa_checkthrottled(sender, rup, "LOSTPASSWORD"))
continue;

rup->lockuntil=t;
rup->lastemailchange=t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does lastemailchange change?

csdb_updateuser(rup);

if(rup->lastauth) {
csdb_createmail(rup, QMAIL_LOSTPW);
} else {
csdb_createmail(rup, QMAIL_NEWACCOUNT); /* user hasn't authed yet and needs to do the captcha */
}

cs_log(sender,"LOSTPASSWORD OK username %s email %s", rup->username, rup->email->content);
chanservstdmessage(sender, QM_MAILQUEUED);
}
}

if(!matched) {
cs_log(sender,"LOSTPASSWORD FAIL email %s",cargv[0]);
chanservstdmessage(sender, QM_BADEMAIL);
return CMD_ERROR;
} else {
chanservstdmessage(sender, QM_DONE);
}

return CMD_OK;
}
3 changes: 2 additions & 1 deletion chanserv/authcmds/newpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "../chanserv.h"
#include "../authlib.h"
#include "../../lib/irc_string.h"
#include "../../lib/hmac.h"
#include "../../core/hooks.h"
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -56,7 +57,7 @@ int csa_donewpw(void *source, int cargc, char **cargv) {
return CMD_ERROR;
}

if (!strcmp(cargv[0],cargv[1])) {
if (!hmac_strcmp(cargv[0],cargv[1])) {
/* If they are the same then continue anyway but don't send the hook later. */
same=1;
}
Expand Down
70 changes: 0 additions & 70 deletions chanserv/authcmds/requestpassword.c

This file was deleted.

107 changes: 107 additions & 0 deletions chanserv/authcmds/resetpassword.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* CMDNAME: resetpassword
* CMDALIASES: resetpass
* CMDLEVEL: QCMD_SECURE | QCMD_NOTAUTHED
* CMDARGS: 4
* CMDDESC: Resets the password.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with:

 * CMDDESC: Change your password using a code that was sent to your email address.
XX
 * CMDHELP: Usage: @UCOMMAND@ <username> <code> <newpassword> <newpassword>
 * CMDHELP: Changes your account password using a code that was sent to your email address. 
 * CMDHELP: Your new password must be at least 6 characters long, contain at least one number
 * CMDHELP: and one letter, and may not contain sequences of letters or numbers, also note
 * CMDHELP: that your password will be truncated to 10 characters.
 * CMDHELP: Your new password will be sent to your registered email address.
 * CMDHELP: Where:
 * CMDHELP: username - your username
 * CMDHELP: code - code you received in an email sent to your registered address
 * CMDHELP: newpassword - your desired new password.  Must be entered the same both times.
 * CMDHELP: Note: due to the sensitive nature of this command, you must send the message to
 * CMDHELP: Note: due to the sensitive nature of this command, you must send the message to
 * CMDHELP: Q@CServe.quakenet.org when using it.

* CMDFUNC: csa_dorespw
* CMDPROTO: int csa_dorespw(void *source, int cargc, char **cargv);
* CMDHELP: Usage: @UCOMMAND@ <account> <newpass> <newpass> <code>
* CMDHELP: Resets your password using the code received on your registered email address, where:
* CMDHELP: username - your username
* CMDHELP: newpass - your desired new password. Must be entered the same both times.
* CMDHELP: code - the code received in the RESET email.
*/

#include "../chanserv.h"
#include "../authlib.h"
#include "../../lib/irc_string.h"
#include "../../lib/hmac.h"
#include <stdio.h>
#include <string.h>

int csa_dorespw(void *source, int cargc, char **cargv) {
reguser *rup;
nick *sender=source;
unsigned int same=0;
int pq;
time_t t;

if (cargc<4) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plaese swap the code so it is before the "newpass" -- the user will probably have to change their pass a few times so putting the code first makes it easier

chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "resetpassword");
return CMD_ERROR;
}

if (!(rup=findreguser(sender, cargv[0])))
return CMD_ERROR;

if (strcmp(cargv[1],cargv[2])) {
chanservstdmessage(sender, QM_PWDONTMATCH); /* Sorry, passwords do not match */
cs_log(sender,"RESETPASS FAIL username %s new passwords don't match (%s vs %s)",rup->username,cargv[1],cargv[2]);
return CMD_ERROR;
}

if (!hmac_strcmp(rup->password,cargv[1])) {
/* If they are the same then continue anyway but don't send the hook later. */
same=1;
}

pq = csa_checkpasswordquality(cargv[1]);
if(pq == QM_PWTOSHORT) {
chanservstdmessage(sender, QM_PWTOSHORT); /* new password too short */
cs_log(sender,"RESETPASS FAIL username %s password too short %s (%zu characters)",rup->username,cargv[1],strlen(cargv[1]));
return CMD_ERROR;
} else if(pq == QM_PWTOWEAK) {
chanservstdmessage(sender, QM_PWTOWEAK); /* new password is weak */
cs_log(sender,"RESETPASS FAIL username %s password too weak %s",rup->username,cargv[1]);
return CMD_ERROR;
} else if(pq == QM_PWTOLONG) {
chanservstdmessage(sender, QM_PWTOLONG); /* new password too long */
cs_log(sender,"RESETPASS FAIL username %s password too long %s",rup->username,cargv[1]);
return CMD_ERROR;
} else if(pq == -1) {
/* all good */
} else {
chanservsendmessage(sender, "unknown error in resetpass.c... contact #help");
return CMD_ERROR;
}

if(UHasStaffPriv(rup) || !rup->lockuntil || hmac_strcmp(cargv[3], csc_generateresetcode(rup->lockuntil, rup->username))) {
chanservstdmessage(sender, QM_BADRESETCODE);
return CMD_ERROR;
}

t=time(NULL);

if(rup->lockuntil > t) {
chanservstdmessage(sender, QM_ACCOUNTLOCKED, rup->lockuntil);
return CMD_ERROR;
}

rup->lockuntil=t+7*24*3600;

if(rup->lastemail) {
freesstring(rup->lastemail);
rup->lastemail=NULL;
}

rup->lastpasschange=t;
csdb_accounthistory_insert(sender, rup->password, cargv[1], NULL, NULL);
setpassword(rup, cargv[1]);

rup->lastauth=t;
chanservstdmessage(sender, QM_PWCHANGED);
cs_log(sender,"RESETPASS OK username %s", rup->username);

#ifdef AUTHGATE_WARNINGS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priv users can't do this at all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newpass can be used by priv accounts, this command can't be

if(UHasOperPriv(rup))
chanservsendmessage(sender, "WARNING FOR PRIVILEGED USERS: you MUST go to https://auth.quakenet.org and login successfully to update the cache, if you do not your old password will still be usable in certain circumstances.");
#endif

csdb_updateuser(rup);
csdb_createmail(rup, QMAIL_NEWPW);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this send out a reset code?
if so: should we, given we know they've just done this from their email?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, i looked at it - reset codes aren't sent for staffers, and also getting blocked on an "if (UHasStaffPriv(..." before (line 68).
Removing this message.


if (!same)
triggerhook(HOOK_CHANSERV_PWCHANGE, sender);

return CMD_OK;
}
31 changes: 18 additions & 13 deletions chanserv/authcmds/sendpassword.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* Automatically generated by refactor.pl.
*
*
* CMDNAME: sendpassword
/* CMDNAME: sendpassword
* CMDALIASES: sendpass
* CMDLEVEL: QCMD_HELPER
* CMDARGS: 1
* CMDDESC: Sends the users current password by email.
* CMDDESC: Sends the user a reset code to the email.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to their email address"

* CMDFUNC: csa_dosendpw
* CMDPROTO: int csa_dosendpw(void *source, int cargc, char **cargv);
* CMDHELP: Usage: @UCOMMAND@ <username>
* CMDHELP: Sends the password for the specified account to the specified users email address.
* CMDHELP: Sends the password for the specified account to the user's email address.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep this as it was

*/

#include "../chanserv.h"
Expand All @@ -21,6 +18,7 @@
int csa_dosendpw(void *source, int cargc, char **cargv) {
reguser *rup;
nick *sender=source;
time_t t;

if (cargc<1) {
chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "sendpassword");
Expand All @@ -36,16 +34,23 @@ int csa_dosendpw(void *source, int cargc, char **cargv) {
return CMD_ERROR;
}

/* we don't reset the throttling timer
rup->lastemailchange=time(NULL);
csdb_updateuser(rup);
*/
t = time(NULL);

if(rup->lastauth) {
csdb_createmail(rup, QMAIL_REQPW);
if(rup->lockuntil && rup->lockuntil > t) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if they have 1 second to go you'll send the same code?
seems a bit harsh!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reset codes work pretty much the same on other commands like RESET, but sure we can change that to.. like, 5 minutes?
I don't believe sending a new one on every request will be helpful (accounting for time for the mail to arrive, the user to use it etc...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not what I'm saying

if the user has 1 second to go you'll send them a useless code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what should i do?
in my opinion, options are:
a) generate a new code if it's the last 5 minutes,
b) send in the email the validity time for the reset code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a), but I'd make it 30 minutes

// Send same reset code.
csdb_createmail(rup, QMAIL_NEWPW);
} else {
csdb_createmail(rup, QMAIL_NEWACCOUNT); /* user hasn't authed yet and needs to do the captcha */
rup->lockuntil=t;
rup->lastemailchange=t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change lastemailchange ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it there though?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastemailchange seems to affect csa_checkthrottled() in authlib.c. Updating the value here makes sense to me in this context.

csdb_updateuser(rup);

if(rup->lastauth) {
csdb_createmail(rup, QMAIL_LOSTPW);
} else {
csdb_createmail(rup, QMAIL_NEWACCOUNT); /* user hasn't authed yet and needs to do the captcha */
}
}

chanservstdmessage(sender, QM_MAILQUEUED);
cs_log(sender,"SENDPASSWORD username %s", rup->username);

Expand Down
1 change: 1 addition & 0 deletions chanserv/batcher/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CONFIG = {
"smtpauth": None,
"templateoptions": {
"bot": "Q9",
"botsecure": "Q9@CServe.test.quakenet.org",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this out of "bot" and "server"

"cleanup": 80,
"securityurl": "http://www.quakenet.org/faq/faq.php?c=160",
"siteurl": "http://www.quakenet.org/",
Expand Down
17 changes: 11 additions & 6 deletions chanserv/batcher/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ def generate_resetcode(config, obj):
obj["lockuntil"] = time.ctime(obj["user.lockuntil"])
obj["resetline"] = "/MSG %(config.bot)s RESET #%(user.username)s %(resetcode)s" % obj

def generate_resetpassword(config, obj):
generate_resetcode(config, obj)
obj["resetline"] = "/MSG %(config.botsecure)s RESETPASSWORD #%(user.username)s <newpass> <newpass> %(resetcode)s" %obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newpassword newpassword (+ put code at beginning)


MAILTEMPLATES = {
"mutators": {
1: generate_url,
2: generate_resetpassword,
3: generate_resetcode,
5: generate_resetcode,
6: generate_activation_url,
Expand Down Expand Up @@ -85,15 +90,15 @@ def generate_resetcode(config, obj):
NB: Save this email for future reference.
""",
},
2: { "subject": "%(config.bot)s password request", "body": """
Your username/password is:
2: { "subject": "%(config.bot)s reset password", "body": """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"password reset request" instead of "reset password"

A password reset was requested for your account, to reset your password please use:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was -> has been

%(resetline)s

Username: %(user.username)s
Password: %(user.password)s
Where <newpass> should be replaced with your desired password.

To auth yourself to %(config.bot)s, type the following command
For more information please visit the resetpassword help link at http://www.quakenet.org/help/q-commands/resetpassword
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newpass -> newpassword

"For more information please visit: https://www.quakenet.org/help/q-commands/resetpassword"

also URL needs to exist


/MSG %(config.bot)s@%(config.server)s AUTH %(user.username)s %(user.password)s
If it was not you who issued this command, please disregard this mail.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If you did not issue this command, you can ignore this email and no changes will made to your account."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, "will made" should be "will be made"

""", },
3: { "subject": "%(config.bot)s password change", "body": """
Your password has recently changed. If this was not requested by you,
Expand Down
2 changes: 1 addition & 1 deletion chanserv/chanserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
#define VALID_ACCOUNT_NAME "\\A[a-z][a-z0-9\\-]+\\Z"

#define QMAIL_NEWACCOUNT 1 /* new account */
#define QMAIL_REQPW 2 /* requestpassword */
#define QMAIL_LOSTPW 2 /* lostpassword */
#define QMAIL_NEWPW 3 /* new password */
#define QMAIL_RESET 4 /* reset account */
#define QMAIL_NEWEMAIL 5 /* new email address */
Expand Down