• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] How to make pasword validation?
#1
Hello i need help with?password validation, so if registered user types wrong password more than 3 times to login, it should kick the user?



PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])

{

? ? if(
dialogid == REGISTER_DIALOG)

? ? {

? ? ? ? if(
response)

? ? ? ? {

? ? ? ? ? ? if(
strlen(inputtext) < || strlen(inputtext) > 24)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? 
SendClientMessage(playerid, -1"SERVER: Your password must be from 3-24 characters.");

? ? ? ? ? ? ? ? return 
ShowPlayerDialog(playeridREGISTER_DIALOGDIALOG_STYLE_PASSWORD"{FFFFFF}Register Account""{FFFFFF}Please enter a password below to register an account:""Enter""Leave");

? ? ? ? ? ? }

? ? ? ? 

? ? ? ? ? ? 
bcrypt_hash(playerid"OnPlayerRegister"inputtext12);

? ? ? ? ? ? return 
1;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? 
Kick(playerid);

? ? ? ? }

? ? }

? ? else if(
dialogid == LOGIN_DIALOG)

? ? {

? ? ? ? if(
response)

? ? ? ? {

? ? ? ? ? ? new 
query[256], field[64];

? ? ? ? ? ? 
format(querysizeof(query), "SELECT `PASS` FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE"DB_Escape(ReturnName(playerid)));

? ? ? ? ? ? 
database_result db_query(server_databasequery);

? ? ? ? ? ? ? if(
db_num_rows(database_result))

? ? ? ? ? ? {

? ? ? ? ? ? ? ? 
db_get_field_assoc(database_result"PASS"fieldsizeof(field));

? ? ? ? ? ? ? ? ? 
bcrypt_verify(playerid"OnPlayerLogin"inputtextfield);

? ? ? ? ? ? }

? ? ? ? ? ? return 
1;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? 
Kick(playerid);

? ? ? ? }

? ? }

? ? return 
1;


  Reply
#2
Code:
public OnPlayerLogin(playerid, bool:success)

{

    if(success)

    {

        DeletePVar(playerid, "loginFails");

        // Logged in code

    }

    else

    {

        SetPVarInt(playerid, "loginFails", (GetPVarInt(playerid, "loginFails")  1));

        if(GetPVarInt(playerid, "loginFails") >= 3)

        {

            SendClientMessage(playerid, -1, "Too many failed login attempts!");

            Kick(playerid);

        }

        else

        {

            SendClientMessage(playerid, -1, "You entered the wrong password, please try again!");

        }

    }

}
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#3
(2021-06-28, 09:41 AM)Pinch Wrote:
Code:
public OnPlayerLogin(playerid, bool:success)

{

? ? if(success)

? ? {

? ? ? ? DeletePVar(playerid, "loginFails");

? ? ? ? // Logged in code

? ? }

? ? else

? ? {

? ? ? ? SetPVarInt(playerid, "loginFails", (GetPVarInt(playerid, "loginFails")  1));

? ? ? ? if(GetPVarInt(playerid, "loginFails") >= 3)

? ? ? ? {

? ? ? ? ? ? SendClientMessage(playerid, -1, "Too many failed login attempts!");

? ? ? ? ? ? Kick(playerid);

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? SendClientMessage(playerid, -1, "You entered the wrong password, please try again!");

? ? ? ? }

? ? }

}



Hi my OnPlayerLogin looks a bit more different so im unsure how to fix the code with the one you sent.



PHP Code:
public OnPlayerLogin(playeridbool:success)

{

if(
success)

{

new 
query[256], field[24];

? ? 
format(querysizeof(query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE"DB_Escape(ReturnName(playerid)));

database_result db_query(server_databasequery);

if(
db_num_rows(database_result))

{

db_get_field_assoc(database_result"SCORE"fieldsizeof(field));

SetPlayerScore(playeridstrval(field));



db_get_field_assoc(database_result"KILLS"fieldsizeof(field));

PlayerInfo[playerid][pKills] = strval(field);



db_get_field_assoc(database_result"DEATHS"fieldsizeof(field));

PlayerInfo[playerid][pDeaths] = strval(field);

}



db_free_result(database_result);

ShowModelSelectionMenu(playeridjoinskin"Select a Skin");



SendClientMessage(playerid, -1"SERVER: You have successfully logged into your account.");

return 
1;

}



else {

Kick(playerid);

}



return 
1;


  Reply


Forum Jump: