cool, finally I've successfully modified chpass alone.
concepts that I apply is, save one argument that has been hashed into the temporary data in the user file, and will compare with the old password ..
nah its this detail ..
static int _handle_chpass_command(t_connection * c, char const *text)
{
unsigned int i,j;
t_account * account;
t_account * temp;
t_hash passhash;
char *command;
char arg1[256];
char arg2[256];
char const * username;
char * pass;
for (i=0; text[i]!=' ' && text[i]!='\0'; i++);
for (; text[i]==' '; i++);
for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get username/pass */
if (j<sizeof(arg1)-1) arg1[j++] = text[i];
arg1[j] = '\0';
for (; text[i]==' '; i++); /* skip spaces */
for (j=0; text[i]!=' ' && text[i]!='\0'; i++)
if (j<sizeof(arg2)-1) arg2[j++] = text[i];
arg2[j] = '\0';
account = conn_get_account(c);
username = conn_get_username(c);
command = arg1;
pass = arg2;
if (arg2[0]=='\0') {
message_send_text(c,message_type_info,c,"Change your password.");
message_send_text(c,message_type_info,c,"Type: /chpass <currentpassword> <newpassword>");
return 0;
}
else {
for (i=0; i<std::strlen(command); i++)
if (std::isupper((int)command[i])) command[i] = std::tolower((int)command[i]);
bnet_hash(&passhash,std::strlen(command),command);
account_set_strattr(account,"TEMP\\Curpass",hash_get_str(passhash));
}
snprintf(msgtemp, sizeof(msgtemp), "Trying to change password for account \"%.64s\" to \"%.128s\"",username,pass);
message_send_text(c,message_type_info,c,msgtemp);
if (!std::strcmp(account_get_strattr(account,"TEMP\\Curpass"),account_get_pass(account))) {
if (std::strlen(pass) > MAX_USERPASS_LEN) {
snprintf(msgtemp, sizeof(msgtemp), "Maximum password length allowed is %d",MAX_USERPASS_LEN);
message_send_text(c,message_type_error,c,msgtemp);
return 0;
}
for (i=0; i<std::strlen(pass); i++)
if (std::isupper((int)pass[i])) pass[i] = std::tolower((int)pass[i]);
bnet_hash(&passhash,std::strlen(pass),pass);
if (account_set_pass(account,hash_get_str(passhash))<0) {
message_send_text(c,message_type_error,c,"Unable to set password.");
return 0;
}
if (account_get_auth_admin(account,NULL) == 1 || account_get_auth_operator(account,NULL) == 1) {
snprintf(msgtemp, sizeof(msgtemp), "Success. Password for account "UID_FORMAT" updated.",account_get_uid(account));
message_send_text(c,message_type_info,c,msgtemp);
snprintf(msgtemp, sizeof(msgtemp), "Hash is: %.128s",hash_get_str(passhash));
message_send_text(c,message_type_info,c,msgtemp);
} else {
snprintf(msgtemp, sizeof(msgtemp), "Success. Password for account %.64s updated.",username);
message_send_text(c,message_type_info,c,msgtemp);
}
return 0;
} else {
message_send_text(c,message_type_error,c,"Unable to change password. Wrong current password!");
return 0;
}
}
and I also had to overcome a mistake if,
/chpass aa bb cc
then the password will be changed only into bb, cc does not include, of course if aa is the old password
I hope this information can be useful and applicable if there is a need
thx...
17 minutes and 58 seconds after:
and this is of screen shoot