Skip to content
Snippets Groups Projects
Commit 6ed2240b authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Detect and reject invalid birthdates during new user registration

e.g. month and day reversed
parent 18596595
No related branches found
No related tags found
No related merge requests found
Pipeline #5792 passed
......@@ -286,7 +286,7 @@ bool sbbs_t::newuser()
if(gettmplt(str, birthdate_template(&cfg, tmp, sizeof tmp), K_EDIT) < 10)
continue;
int age = getage(&cfg, parse_birthdate(&cfg, str, tmp, sizeof(tmp)));
if(age >= 0 && age <= 200) { // TODO: Configurable min/max user age
if(age >= 1 && age <= 200) { // TODO: Configurable min/max user age
SAFECOPY(useron.birth, tmp);
break;
}
......
......@@ -983,6 +983,7 @@ char* getbirthdstr(scfg_t* cfg, const char* birth, char* buf, size_t max)
/****************************************************************************/
/* Returns the age derived from the string 'birth' in the format CCYYMMDD */
/* or legacy: MM/DD/YY or DD/MM/YY */
/* Returns 0 on invalid 'birth' date */
/****************************************************************************/
int getage(scfg_t* cfg, const char *birth)
{
......@@ -1003,7 +1004,10 @@ int getage(scfg_t* cfg, const char *birth)
int year = getbirthyear(birth);
int age = (1900 + tm.tm_year) - year;
int mon = getbirthmonth(cfg, birth);
if(mon > tm.tm_mon || (mon == tm.tm_mon && getbirthday(cfg, birth) > tm.tm_mday))
int day = getbirthday(cfg, birth);
if(mon < 1 || mon > 12 || day < 1 || day > 31)
return 0;
if(mon > tm.tm_mon || (mon == tm.tm_mon && day > tm.tm_mday))
age--;
return age;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment