| 32 |
#include <mysql/mysql.h> |
#include <mysql/mysql.h> |
| 33 |
#include <sys/param.h> |
#include <sys/param.h> |
| 34 |
|
|
| 35 |
|
static const int BBS_username_min_len = 3; // common len = 5, special len = 3 |
| 36 |
|
static const int BBS_password_min_len = 5; // legacy len = 5, current len = 6 |
| 37 |
|
|
| 38 |
int bbs_login(void) |
int bbs_login(void) |
| 39 |
{ |
{ |
| 40 |
char username[BBS_username_max_len + 1]; |
char username[BBS_username_max_len + 1]; |
| 117 |
// Verify format |
// Verify format |
| 118 |
for (i = 0; ok && username[i] != '\0'; i++) |
for (i = 0; ok && username[i] != '\0'; i++) |
| 119 |
{ |
{ |
| 120 |
if (!(isalpha(username[i]) || (i > 0 && isdigit(username[i])))) |
if (!(isalpha(username[i]) || (i > 0 && (isdigit(username[i]) || username[i] == '_')))) |
| 121 |
{ |
{ |
| 122 |
ok = 0; |
ok = 0; |
| 123 |
} |
} |
| 124 |
} |
} |
| 125 |
if (ok && (i < 3 || i > 12)) |
if (ok && (i < BBS_username_min_len || i > BBS_username_max_len)) |
| 126 |
{ |
{ |
| 127 |
ok = 0; |
ok = 0; |
| 128 |
} |
} |
| 133 |
ok = 0; |
ok = 0; |
| 134 |
} |
} |
| 135 |
} |
} |
| 136 |
if (ok && (i < 5 || i > 12)) |
if (ok && (i < BBS_password_min_len || i > BBS_password_max_len)) |
| 137 |
{ |
{ |
| 138 |
ok = 0; |
ok = 0; |
| 139 |
} |
} |
| 506 |
} |
} |
| 507 |
|
|
| 508 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 509 |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
"INSERT INTO user_online(SID, UID, ip, current_action, login_tm, last_tm) " |
| 510 |
"VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())", |
"VALUES('Telnet_Process_%d', %d, '%s', 'LOGIN', NOW(), NOW())", |
| 511 |
getpid(), BBS_priv.uid, hostaddr_client); |
getpid(), BBS_priv.uid, hostaddr_client); |
| 512 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 513 |
{ |
{ |
| 582 |
} |
} |
| 583 |
|
|
| 584 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 585 |
"UPDATE user_online SET current_action = '%s', last_tm=NOW() " |
"UPDATE user_online SET current_action = '%s', last_tm = NOW() " |
| 586 |
"WHERE SID = 'Telnet_Process_%d'", |
"WHERE SID = 'Telnet_Process_%d'", |
| 587 |
BBS_current_action, getpid()); |
BBS_current_action, getpid()); |
| 588 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |