How to make pasword validation? - CrypticSin - 2021-06-27
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(playerid, dialogid, response, listitem, inputtext[])
{
? ? if(dialogid == REGISTER_DIALOG)
? ? {
? ? ? ? if(response)
? ? ? ? {
? ? ? ? ? ? if(strlen(inputtext) < 3 || strlen(inputtext) > 24)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? SendClientMessage(playerid, -1, "SERVER: Your password must be from 3-24 characters.");
? ? ? ? ? ? ? ? return ShowPlayerDialog(playerid, REGISTER_DIALOG, DIALOG_STYLE_PASSWORD, "{FFFFFF}Register Account", "{FFFFFF}Please enter a password below to register an account:", "Enter", "Leave");
? ? ? ? ? ? }
? ? ? ?
? ? ? ? ? ? bcrypt_hash(playerid, "OnPlayerRegister", inputtext, 12);
? ? ? ? ? ? return 1;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? Kick(playerid);
? ? ? ? }
? ? }
? ? else if(dialogid == LOGIN_DIALOG)
? ? {
? ? ? ? if(response)
? ? ? ? {
? ? ? ? ? ? new query[256], field[64];
? ? ? ? ? ? format(query, sizeof(query), "SELECT `PASS` FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE", DB_Escape(ReturnName(playerid)));
? ? ? ? ? ? database_result = db_query(server_database, query);
? ? ? ? ? ? ? if(db_num_rows(database_result))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? db_get_field_assoc(database_result, "PASS", field, sizeof(field));
? ? ? ? ? ? ? ? ? bcrypt_verify(playerid, "OnPlayerLogin", inputtext, field);
? ? ? ? ? ? }
? ? ? ? ? ? return 1;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? Kick(playerid);
? ? ? ? }
? ? }
? ? return 1;
}
RE: How to make pasword validation? - Pinch - 2021-06-28
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!");
}
}
}
RE: How to make pasword validation? - CrypticSin - 2021-06-28
(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(playerid, bool:success)
{
if(success)
{
new query[256], field[24];
? ? format(query, sizeof(query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE", DB_Escape(ReturnName(playerid)));
database_result = db_query(server_database, query);
if(db_num_rows(database_result))
{
db_get_field_assoc(database_result, "SCORE", field, sizeof(field));
SetPlayerScore(playerid, strval(field));
db_get_field_assoc(database_result, "KILLS", field, sizeof(field));
PlayerInfo[playerid][pKills] = strval(field);
db_get_field_assoc(database_result, "DEATHS", field, sizeof(field));
PlayerInfo[playerid][pDeaths] = strval(field);
}
db_free_result(database_result);
ShowModelSelectionMenu(playerid, joinskin, "Select a Skin");
SendClientMessage(playerid, -1, "SERVER: You have successfully logged into your account.");
return 1;
}
else {
Kick(playerid);
}
return 1;
}
|