Login -
ihatetn931 - 17.07.2010
How can i make this where if the password is wrong it won't logg you in.
pawn Код:
public OnPlayerLogin(playerid,password[])
{
if(IsPlayerConnected(playerid)) {
new DataString[128], Query[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format( Query, sizeof( Query ), "SELECT * FROM `players` WHERE `Username` = '%s'",pname);
mysql_query(Query);
mysql_store_result();
mysql_fetch_field("id", DataString);
PlayerInfo[playerid][pID] = strval(DataString);
PlayerInfo[playerid][pID] = PlayerInfo[playerid][pID];
mysql_fetch_field("Password", DataString);
PlayerInfo[playerid][pKey] = strval(DataString);
Basically what i'm trying to say is how can i make it detect if the password is right when you enter it in to the dialog and it sends you to this function. Cause as of now when i enter any password it logs me in
Re: Login -
[HiC]TheKiller - 17.07.2010
pawn Код:
if(strlen(password) != 0) && !strcmp(password, DataString)) //Pass is right.
Re: Login -
ihatetn931 - 17.07.2010
I tried it and i got this
Код:
\\SERVER\sa-mp server\gamemodes\SWRP.pwn(6197) : error 029: invalid expression, assumed zero
\\SERVER\sa-mp server\gamemodes\SWRP.pwn(6197) : error 001: expected token: ";", but found ")"
\\SERVER\sa-mp server\gamemodes\SWRP.pwn(6197) : error 029: invalid expression, assumed zero
\\SERVER\sa-mp server\gamemodes\SWRP.pwn(6197) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
Re: Login -
Grim_ - 17.07.2010
pawn Код:
if((strlen(password) != 0) && !strcmp(password, DataString))
Re: Login -
ihatetn931 - 17.07.2010
That one worked, now the other question is where do i put it? I've tried it where the isplayerconnected and it did the same thing
Re: Login -
Grim_ - 17.07.2010
Oh, try this:
pawn Код:
if(strlen(password) == 0 || strcmp(password, DataString, false) != 0) return 1; // Incorrect password, stop them from logging in.
And put it under this line:
Re: Login -
ihatetn931 - 17.07.2010
Sorry but it didn't work
Here is where it's called
pawn Код:
if(dialogid == 2) {
if(!strlen(inputtext)) {
SendClientMessage(playerid, 0xFFFFFFFF, "Your Password Cannot be left Blank"); Kick(playerid);
ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login to your account","Note - A account with this name was found inside the database,\n If this is your account,type in your password\n if not press cancel!","Login","Cancel");
return 1;
}
if(!response){ SendClientMessage(playerid, 0xFFFFFFFF, "You canceled!"); Kick(playerid); return 0; }
//Encrypt(inputtext);
OnPlayerLogin(playerid,inputtext);
}
this is how i have put it
pawn Код:
public OnPlayerLogin(playerid,password[])
{
if(IsPlayerConnected(playerid)) {
new DataString[128], Query[128], pname[MAX_PLAYER_NAME];
GetPlayerName(playerid, pname, sizeof(pname));
format( Query, sizeof( Query ), "SELECT * FROM `players` WHERE `Username` = '%s'",pname);
mysql_query(Query);
mysql_store_result();
if(strlen(password) == 0 || strcmp(password, DataString, false) != 0) return 1;
mysql_fetch_field("id", DataString);
PlayerInfo[playerid][pID] = strval(DataString);
PlayerInfo[playerid][pID] = PlayerInfo[playerid][pID];
mysql_fetch_field("Password", DataString);
PlayerInfo[playerid][pKey] = strval(DataString);
This is what it does after it loads all the data
pawn Код:
mysql_fetch_field("Carkey3", DataString);
PlayerInfo[playerid][pPcarkey3] = strval(DataString);
// }
}
else {
printf("[ERROR] OnplayerLogin() was called, but to a non-connected ID.", playerid);
GetFromAccount(PlayerInfo[playerid][pID], "Password", PlayerInfo[playerid][pKey]);
ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login to your account","Note - A account with this name was found inside the database,\n If this is your account,type in your password\n if not press cancel!","Login","Cancel");
SendClientMessage(playerid, 0xFFFFFFFF, "Password does not match the username!");
LoginTry[playerid] += 1;
if(LoginTry[playerid] == MAX_TRY) {
SendClientMessage(playerid, COLOR_SYSTEM, "-------------------------------");
SendClientMessage(playerid, COLOR_GREEN, "You Have been banned from blahh");
SendClientMessage(playerid, COLOR_GREEN, "Admin who banned you - SYSTEM");
SendClientMessage(playerid, COLOR_GREEN, "Reason - Failure to login to account maximum times");
SendClientMessage(playerid, COLOR_GREEN, "Type - Perma. Ban");
SendClientMessage(playerid, COLOR_GREEN, "If you wish to complain goto site");
SendClientMessage(playerid, COLOR_SYSTEM, "-Press F8 to take a picture of this-");
SendClientMessage(playerid, COLOR_SYSTEM, "-------------------------------");
//BanEx(playerid, "Failure to login 3 times");
return 1;
}
}
Maybe this will help ya understand how the code works
This is where is sends it to the dialog
pawn Код:
public OnPlayerRequestClass(playerid)
{
SetPlayerCameraPos(playerid, -2604.2324,490.6546,68.6727);
SetPlayerCameraLookAt(playerid, -2381.7639,793.5422,101.3817);
SetPlayerPos(playerid, -2381.7639,793.5422,101.3817);
ClearChat(playerid);
new Query[128], Name[MAX_PLAYER_NAME], EscapedName[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
mysql_real_escape_string(Name, EscapedName);
#pragma unused Name
format(Query, sizeof(Query), "SELECT `id` FROM `players` WHERE `Username` = '%s'", EscapedName);
mysql_query(Query);
mysql_store_result();
//==============================================================================================//
if(mysql_num_rows() >= 1)
{
if(mysql_num_rows() >= 2)
{
//mysql_free_result();
SendClientMessage(playerid, COLOR_WHITE, "There seems to be duplicates of your account, please contact a high-level admin.");
Kick( playerid );
}
else
{
PlayerInfo[playerid][pID] = mysql_fetch_int();
//mysql_free_result();
ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login to your account.","Note - A account with this name was found inside the database,\n If this is your account,type in your password\n if not press cancel.","Login","Cancel");
}
return 1;
}
else
{
//mysql_free_result();
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register your account.","Note - A account with this name was not found inside the database.\n if you would like to register this account,\n type in the password you would like to tegister with.","Register","Cancel");
return 1;
}
}
Re: Login -
Grim_ - 17.07.2010
Sorry, place it under this line:
pawn Код:
PlayerInfo[playerid][pKey] = strval(DataString);
However, that won't work because you are converting the password from the database into an integer. Why are you doing so? (using strval(DataString); )
Re: Login -
ihatetn931 - 17.07.2010
I dunno anything about mysql and i'm still trying to learn pawn, I dunno everything just yet but i'm trying. I can do most things just my weak points are files and ect
Re: Login -
Grim_ - 17.07.2010
Well then replace that line with:
pawn Код:
strmid(PlayerInfo[playerid][pKey], DataString, 0, sizeof(DataString));