23.08.2009, 20:56
I make a register system in mysql, now i need create the /login command but i dont know how to take the "password" from the mysql for use in the pwn
format(query,sizeof(query),"SELECT Whatever FROM `table` WHERE Username = "%s" AND Password = "%s",name,params);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
//Login success
}
else
{
//Login failed
}
if(!strcmp(cmdtext, "/login", true, 3)) // 3 is the length of /me
{
if(cmdtext[9] == 0) {
SendClientMessage(playerid, COLOR_GREY, "Utiliza: /login [password]");
return 1;
}
else
{
if(logueado == 1)
{
SendClientMessage(playerid, COLOR_YELLOW, "Ya estas logueado");
}
else
{
new name[128];
new query[128];
new password = cmdtext[7];
GetPlayerName(playerid, name, sizeof(name));
format(query, sizeof(query), "SELECT id FROM `players` WHERE Nombre = '%s' AND Password = '%s'" , name, password);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_num_rows() > 0)
{
logueado = 1;
SendClientMessage(playerid, COLOR_GREEN, "Login Correcto. Bienvenido");
}
else
{
if(intentos == 3)
{
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Limites de intentos por contraseсa. Has sido Kickeado.");
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
Kick(playerid);
}
else
{
intentos = intentos +1;
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Contraseсa incorrecta.");
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
}
}
}
}
return 1;
}
Originally Posted by Joe Staff
Shouldn't it be "SELECT * FROM mytable WHERE ..." ? I've made my own MySQL login system before and I think that doing "SELECT Whatever" would select a column called 'Whatever' whereas the '*' is all columns. You could also do "SELECT Username,Password FROM mytable ..." and that would get you the columns you're looking for anyway.
|
if(!strcmp(cmdtext, "/login", true, 3)) // 3 is the length of /me
Originally Posted by JaTochNietDan
Quote:
Zafire are you using any type of encryption on the passwords? EDIT: I just noticed this.. pawn Code:
![]() |
Originally Posted by JaTochNietDan
The example I gave you will check if the password = the string used in /login.
|
if(!strcmp(cmdtext, "/login", true, 6))
{
if(cmdtext[9] == 0)
{
SendClientMessage(playerid, COLOR_GREY, "Utiliza: /login [password]");
return 1;
}
else
{
if(logueado == 1)
{
SendClientMessage(playerid, COLOR_YELLOW, "Ya estas logueado");
}
else
{
new name[128];
new query[128];
new pass = cmdtext[7];
GetPlayerName(playerid, name, sizeof(name));
format(query, sizeof(query),"SELECT Whatever FROM `table` WHERE Username = '%s' AND Password = '%s'", name, pass);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_num_rows() > 0)
{
logueado = 1;
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Has sido logueado correctamente.");
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
}
else
{
if(intentos == 3)
{
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Limites de intentos por contraseсa. Has sido Kickeado.");
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
Kick(playerid);
}
else
{
intentos = intentos +1;
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Contraseсa incorrecta.");
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
}
}
}
}
return 1;
}
Originally Posted by JaTochNietDan
Quote:
Zafire are you using any type of encryption on the passwords? EDIT: I just noticed this.. pawn Код:
![]() |
format(query, sizeof(query),"SELECT Whatever FROM `table` WHERE Username = '%s' AND Password = '%s'", name, pass); samp_mysql_query(query); samp_mysql_store_result(); |
if(!strcmp(cmdtext, "/login", true, 6))
{
if(cmdtext[9] == 0)
{
SendClientMessage(playerid, COLOR_GREY, "Utiliza: /login [password]");
return 1;
}
else
{
if(logueado == 1)
{
SendClientMessage(playerid, COLOR_YELLOW, "Ya estas logueado");
}
else
{
new name[128];
new query[128];
new pass = cmdtext[7];
GetPlayerName(playerid, name, sizeof(name));
format(query, sizeof(query),"SELECT id FROM players WHERE Nombre = '%s' AND Password = '%s'", name, pass);
samp_mysql_query(query);
samp_mysql_store_result();
if(samp_mysql_num_rows() > 0)
{
logueado = 1;
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Has sido logueado correctamente.");
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
}
else
{
if(intentos == 3)
{
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Limites de intentos por contraseсa. Has sido Kickeado.");
SendClientMessage(playerid, COLOR_GREEN, "________________________________________________________");
Kick(playerid);
}
else
{
intentos = intentos +1;
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
SendClientMessage(playerid, COLOR_YELLOW, "Contraseсa incorrecta.");
SendClientMessage(playerid, COLOR_GREEN, "_________________________________________");
}
}
}
}
return 1;
}
print(pass);
Originally Posted by JaTochNietDan
Use
pawn Код:
|
format(pass2, sizeof(pass2),"%s", pass);
SendClientMessage(playerid, COLOR_YELLOW, pass2);
Originally Posted by JaTochNietDan
Ok fail? Alex just pointed out to me that you're "pass" is not a string...
It should be new pass[20] = cmdtext[7]; Anyway since that's a guarenteed fix, you also need to use mysql_escape_string(pass,pass); before setting the query string, so that you escape any injection vulnerabilities. |
C:\Documents and Settings\Administrador\Mis documentos\Samp Server\gamemodes\nfs.pwn(475) : error 008: must be a constant expression; assumed zero
Originally Posted by ssǝן‾ʎ
When you get your code working DO NOT type this, you'll loose the database:
Код:
/login '; DROP TABLE players; |
samp_mysql_get_field("The_password_in_your_language",pass);