17.03.2019, 11:31
PHP код:
checkName(playerid, name[]){
new find = strfind(name, "_", false);
if(find == 0) return playerDialogs(playerid, USERNAMEINVALID_DIALOG), 0;
for(new i, j = strlen(name); i < j; i++){
if(i == find) continue; // skips '_' character from being checked
else if(i == 0){
if(name[i] >= 'A' && name[i] <= 'Z') continue;
else {playerDialogs(playerid, FIRSTNAMENOTCAP_DIALOG); break;}
}else if(i == find+1){
if(name[i] >= 'A' && name[i] <= 'Z') continue;
else {playerDialogs(playerid, LASTNAMENOTCAP_DIALOG); break;}
}else{
if(name[i] >= 'a' && name[i] <= 'z') continue;
else if(name[i] >= 0 && name[i] <= 9) {playerDialogs(playerid, USERNAMEHASNUMBER_DIALOG); break;}
else {playerDialogs(playerid, USERNAMESPECIALCHARS_DIALOG); break;}
}
}
inline characterCheck(){
if(cache_num_rows() != 0){
cache_get_value(0, "password", playerData[playerid][password], MAX_PASSWORD);
cache_get_value(0, "salt", playerData[playerid][salt], MAX_SALT);
playerDialogs(playerid, LOGIN_DIALOG);
}else{
playerDialogs(playerid, REGISTER_DIALOG);
}
}
new query[38 + MAX_USERNAME + 13];
mysql_format(db, query, sizeof query, "SELECT * FROM %e WHERE username = '%e'",
USER_TABLE, playerData[playerid][username]);
mysql_tquery_inline(db, query, using inline characterCheck);
return 1;
}
I just need to check if :
Код:
the username can be checked with '_'
Код:
caps on both lastname and firstname which looks like this Ross_Weis
Код:
check if there are numbers
Код:
finally if there are special chars.
This is for my server and since I'm a security check freak... and a security perfectionist... I wish this fully working for my server...
Dislaimer:
I also have not searched the forum so much to see if this has been already been made or not...
the username has already been fetch on OnPlayerConnect so that's already not a problem...