#1

i was making a login command for an admin system...
but when i try to login everytime it success... i mean any password is working -.-
here is my command:

Код:
dcmd_login(playerid,params[])
{
  if (PlayerInfo[playerid][LoggedIn] == 1) return SendClientMessage(playerid,RED,"You are already logged in.");
  if (!strlen(params)) return SendClientMessage(playerid,RED,"USAGE: '/login [password]'");
	new pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid,pName,sizeof(pName));
	new pFile[256];
	format(pFile,sizeof(pFile),File,pName);
	PlayerInfo[playerid][Password] = dini_Int(pFile,"Password");
	new param = strval(params);
	if(param != PlayerInfo[playerid][Password])
	{
	SendClientMessage(playerid,RED,"Invalid Password!");
	}
	if(param == PlayerInfo[playerid][Password])
	{
	SendClientMessage(playerid,GREEN,"You are now logged-in!");
	}
	
	return 1;
}
any help??
Reply
#2

PlayerInfo[playerid][Password] needs to be a string and
pawn Код:
PlayerInfo[playerid][Password] = dini_Get(pFile,"Password");
is correct, since passwords are strings, not integers (unless you can only have numbers for passwords on your server)

You can't do this
pawn Код:
new param = strval(params);
that will try and transform your string into a number and will always return 0, since you don't have any numbers in your password.
And since the same thing happens here
pawn Код:
PlayerInfo[playerid][Password] = dini_Int(pFile,"Password");
then both variables hold zero, which means every login will be correct.

Use strcmp for comparing strings

https://sampwiki.blast.hk/wiki/Strcmp
Reply
#3

Quote:
Originally Posted by dice7
PlayerInfo[playerid][Password] needs to be a string and
pawn Код:
PlayerInfo[playerid][Password] = dini_Get(pFile,"Password");
is correct, since passwords are strings, not integers (unless you can only have numbers for passwords on your server)

You can't do this
pawn Код:
new param = strval(params);
that will try and transform your string into a number and will always return 0, since you don't have any numbers in your password.
And since the same thing happens here
pawn Код:
PlayerInfo[playerid][Password] = dini_Int(pFile,"Password");
then both variables hold zero, which means every login will be correct.

Use strcmp for comparing strings

https://sampwiki.blast.hk/wiki/Strcmp
thx...
lol i made a big mistake xD
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)