[Help] With strcmp in a MySql login script!
#1

I'm trying to make this script works for a few days by myself. I dont have many knowledge over arrays so i cant figure out how to do it.
Please help meeeahh!

Quote:

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == login)
{
new query[256];
format(query,sizeof(query),"SELECT `senha` FROM `usuario` WHERE `login` = '%s'",PlayerName(playerid));
mysql_query(query);
mysql_store_result();
PlayerStatistics[playerid][PASSWORD] = mysql_fetch_int();
if(strcmp( inputtext, PlayerStatistics[ playerid ][ PASSWORD ], true ) == 0 )
{
Logged[playerid]==1;
printf("[Login]: O usuario `%s` fez login com sucesso!",PlayerName(playerid));
SendClientMessage(playerid, COR_INFO, "You've been succesfully authed.");
new welcome[256];
format(welcome,sizeof(welcome),"Welcome back '%s' ",PlayerName(playerid));
SendClientMessage(playerid, COR_INFO, welcome);
}
else
{
new welcome[256];
format(welcome,sizeof(welcome),"Bad, bad password. Password entered: '%s' ",inputtext);
SendClientMessage(playerid, COR_BRANCO, welcome);
SendClientMessage( playerid, COR_BRANCO, "Bad, bad password. To avoid lammers you will be automatically disconnected." );
SetTimer("kicklogin", 10000, false);
}
return 0;
}
return 0;
}

I think the problem is in the red part. Im using the a_mysql.inc plugin, that one that almost everyone has.
In the password entered answer, it comes the right one. And in the MySql log:

Quote:

[13:16:25] ---------------------------

[13:16:25] MySQL Debugging activated (04/21/10)

[13:16:25] ---------------------------

[13:16:25]

[13:16:56] >> mysql_query( Connection handle: 1 )

[13:16:56] CMySQLHandler::Query(SELECT `login` FROM `usuario` WHERE `login` = 'Lucca_Xavier') - Successfully executed.

[13:16:56] >> mysql_store_result( Connection handle: 1 )

[13:16:56] CMySQLHandler::StoreResult() - Result was stored.

[13:16:56] >> mysql_num_rows( Connection handle: 1 )

[13:16:56] CMySQLHandler::NumRows() - Returned 1 rows(s)

[13:16:59] >> mysql_query( Connection handle: 1 )

[13:16:59] CMySQLHandler::Query(SELECT `senha` FROM `usuario` WHERE `login` = 'Lucca_Xavier') - Successfully executed.

[13:16:59] >> mysql_store_result( Connection handle: 1 )

[13:16:59] CMySQLHandler::StoreResult() - Result was stored.

[13:16:59] >> mysql_fetch_int( Connection handle: 1 )

[13:16:59] CMySQLHandler::FetchRow() - Return: MYPASSWORD!

Reply
#2

just bumping it, i really need an answer.
I can think about remunerating who can solve this for me trough paypal....
Reply
#3

You're trying to load the password as an integer, that won't work. Load it as a STRING.
Reply
#4

how can i use the password as a string instead of an integer value?!
Reply
#5

Quote:
Originally Posted by kariok
how can i use the password as a string instead of an integer value?!
mysql_fetch_string()

Not only that, you're not getting any specific field.

I'll update this for you and this shall work.

There's also NO need for a 256-cell string.

This may not work as the field names may be different for you, so make sure you change it all up if you need to.

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
  if (dialogid == login)
  {
        new query[ 128 ], EscapedPass[ 128 ];
       
        mysql_real_escape_string( inputtext, EscapedPass );
       
        format(query,sizeof(query), "SELECT * FROM `usuario` WHERE `login` = '%s' AND `password` = '%s'", PlayerName( playerid ), EscapedPass );
        mysql_query( query );
        mysql_store_result();
       
        if( mysql_num_rows() >= 1 )
        {
          // Success.
        }
        else
        {
          // Failed.
        }
       
        mysql_free_result();
    }
   
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)