Pincode Functionality Extension

Added some options to allow or disallow certain combinations in the pincode as aegis has it.
In AEGIS it is not allowed to use pincodes like 0000 or 1111 where the pincode only contains 1 character. It is also not allowed to use sequences like 1234 or 5678.

In addition to the official check, which only disallows ascending sequences I also added descending ones.
This commit is contained in:
Lemongrass3110 2015-10-07 00:15:11 +02:00
parent 64d2463e25
commit 10c2dc10dc
4 changed files with 104 additions and 8 deletions

View File

@ -196,6 +196,14 @@ pincode_maxtry: 3
// Default: yes
pincode_force: yes
// Are repeated numbers allowed?
// Default: no
pincode_allow_repeated: no
// Are sequential numbers allowed?
// Default: no
pincode_allow_sequential: no
//===================================
// Addon system
//===================================

View File

@ -2588,6 +2588,8 @@ void char_set_defaults(){
charserv_config.pincode_config.pincode_changetime = 0;
charserv_config.pincode_config.pincode_maxtry = 3;
charserv_config.pincode_config.pincode_force = true;
charserv_config.pincode_config.pincode_allow_repeated = false;
charserv_config.pincode_config.pincode_allow_sequential = false;
charserv_config.charmove_config.char_move_enabled = true;
charserv_config.charmove_config.char_movetoused = true;
@ -2826,6 +2828,10 @@ bool char_config_read(const char* cfgName, bool normal){
charserv_config.pincode_config.pincode_maxtry = atoi(w2);
} else if (strcmpi(w1, "pincode_force") == 0) {
charserv_config.pincode_config.pincode_force = config_switch(w2);
} else if (strcmpi(w1, "pincode_allow_repeated") == 0) {
charserv_config.pincode_config.pincode_allow_repeated = config_switch(w2);
} else if (strcmpi(w1, "pincode_allow_sequential") == 0) {
charserv_config.pincode_config.pincode_allow_sequential = config_switch(w2);
} else if (strcmpi(w1, "char_move_enabled") == 0) {
charserv_config.charmove_config.char_move_enabled = config_switch(w2);
} else if (strcmpi(w1, "char_movetoused") == 0) {

View File

@ -78,6 +78,7 @@ enum pincode_state {
PINCODE_NOTSET = 2,
PINCODE_EXPIRED = 3,
PINCODE_NEW = 4,
PINCODE_ILLEGAL = 5,
PINCODE_PASSED = 7,
PINCODE_WRONG = 8,
PINCODE_MAXSTATE
@ -87,6 +88,8 @@ struct Pincode_Config {
int pincode_changetime;
int pincode_maxtry;
bool pincode_force;
bool pincode_allow_repeated;
bool pincode_allow_sequential;
};
struct CharMove_Config {
bool char_move_enabled;

View File

@ -19,6 +19,7 @@
#include <stdlib.h>
bool pincode_allowed( char* pincode );
//------------------------------------------------
//Add On system
@ -158,6 +159,76 @@ int chclif_parse_pincode_check( int fd, struct char_session_data* sd ){
return 1;
}
/*
* Helper function to check if a new pincode contains illegal characters or combinations
*/
bool pincode_allowed( char* pincode ){
int i;
char c, n, compare[PINCODE_LENGTH+1];
memset( compare, 0, PINCODE_LENGTH+1);
// Sanity check for bots to prevent errors
for( i = 0; i < PINCODE_LENGTH; i++ ){
c = pincode[i];
if( c < '0' || c > '9' ){
return false;
}
}
// Is it forbidden to use only the same character?
if( !charserv_config.pincode_config.pincode_allow_repeated ){
c = pincode[0];
// Check if the first character equals the rest of the input
for( i = 0; i < PINCODE_LENGTH; i++ ){
compare[i] = c;
}
if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){
return false;
}
}
// Is it forbidden to use a sequential combination of numbers?
if( !charserv_config.pincode_config.pincode_allow_sequential ){
c = pincode[0];
// Check if it is an ascending sequence
for( i = 0; i < PINCODE_LENGTH; i++ ){
n = c + i;
if( n > '9' ){
compare[i] = '0' + ( n - '9' ) - 1;
}else{
compare[i] = n;
}
}
if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){
return false;
}
// Check if it is an descending sequence
for( i = 0; i < PINCODE_LENGTH; i++ ){
n = c - i;
if( n < '0' ){
compare[i] = '9' - ( '0' - n ) + 1;
}else{
compare[i] = n;
}
}
if( strncmp( pincode, compare, PINCODE_LENGTH + 1 ) == 0 ){
return false;
}
}
return true;
}
/*
* Client request to change pincode
*/
@ -180,12 +251,16 @@ int chclif_parse_pincode_change( int fd, struct char_session_data* sd ){
if( !char_pincode_compare( fd, sd, oldpin ) )
return 1;
char_pincode_decrypt(sd->pincode_seed,newpin);
if( pincode_allowed(newpin) ){
chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
strncpy(sd->pincode, newpin, sizeof(newpin));
ShowInfo("Pincode changed for AID: %d\n", sd->account_id);
chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
strncpy(sd->pincode, newpin, sizeof(newpin));
ShowInfo("Pincode changed for AID: %d\n", sd->account_id);
chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
}else{
chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL );
}
}
return 1;
}
@ -207,10 +282,14 @@ int chclif_parse_pincode_setnew( int fd, struct char_session_data* sd ){
char_pincode_decrypt( sd->pincode_seed, newpin );
chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
strncpy( sd->pincode, newpin, strlen( newpin ) );
if( pincode_allowed(newpin) ){
chlogif_pincode_notifyLoginPinUpdate( sd->account_id, newpin );
strncpy( sd->pincode, newpin, strlen( newpin ) );
chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
chclif_pincode_sendstate( fd, sd, PINCODE_PASSED );
}else{
chclif_pincode_sendstate( fd, sd, PINCODE_ILLEGAL );
}
}
return 1;
}