MySQL Login problem.. -
TheBluec0de - 22.11.2011
When i enter the correct password give me a incorrect password why ? the password are hashed with SHA1, the database is in localhost
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOGO_REGISTRAZIONE)
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 10)
{
format(Stringa, sizeof(Stringa), "Inserisci una password tra 1-10 caratteri \nBenvenuto %s nel server Italian Las Venturas!\n\n Il tuo account non risulta registrato.\nRegistra un account inserendo la password qui sotto:", GetPlayerNomeEx(playerid));
ShowPlayerDialog(playerid, DIALOGO_REGISTRAZIONE, DIALOG_STYLE_PASSWORD, "Registrazione", Stringa, "Registra", "Cancella");
}
else
{
mysql_real_escape_string(inputtext, EscPassword);
format(Query, sizeof(Query), "INSERT INTO Utenti (Nome, Password, Ip, Soldi, Punteggio, Uccisioni, Morti) VALUES('%s', SHA1('%s'), '%s', 0, 0, 0, 0)", GetPlayerNomeEx(playerid), EscPassword, GetPlayerIpEx(playerid));
mysql_query(Query);
SendClientMessage(playerid, -1, "SERVER: Registrazione effettuata");
Registrato[playerid] = 1;
}
}
else if(!response) return Kick(playerid);
}
if(dialogid == DIALOGO_ACCESSO)
{
if(response)
{
mysql_real_escape_string(inputtext, EscPassword);
format(Query, sizeof(Query), "SELECT * FROM `Utenti` WHERE `Nome` = '%s' AND `Password` = SHA1('%s')", GetPlayerNomeEx(playerid), EscPassword);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI]++;
if(UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI] == MAX_ACC_FALLITI)
{
SendClientMessage(playerid, -1, "SERVER: Hai superato il limite massimo di tentativi per accedere. Sei stato kickato.");
Kick(playerid);
}
format(Stringa, sizeof(Stringa), "Tentativo accesso %d/%d. A %d tentativi verrai kickato \nBentornato %s nel server Italian Las Venturas!\n\n Il tuo account risulta registrato.\nInserisci la password per accedere:", UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI], MAX_ACC_FALLITI, MAX_ACC_FALLITI, GetPlayerNomeEx(playerid));
ShowPlayerDialog(playerid, DIALOGO_ACCESSO, DIALOG_STYLE_PASSWORD, "Accesso", Stringa, "Accedi", "Cancella");
}
else
{
new MySQLStringa[20];
while (mysql_retrieve_row())
{
mysql_fetch_field_row(MySQLStringa, "Soldi"); UtenteInfo[playerid][STATO_UTENTE_SOLDI] = strval(MySQLStringa);
mysql_fetch_field_row(MySQLStringa, "Punteggio"); SetPlayerScore(playerid, strval(MySQLStringa));
mysql_fetch_field_row(MySQLStringa, "Uccisioni"); UtenteInfo[playerid][STATO_UTENTE_UCCISIONI] = strval(MySQLStringa);
mysql_fetch_field_row(MySQLStringa, "Morti"); UtenteInfo[playerid][STATO_UTENTE_MORTI] = strval(MySQLStringa);
}
mysql_free_result();
SendClientMessage(playerid, -1, "SERVER: Accesso effettuato");
Accesso[playerid] = 1;
}
mysql_free_result();
}
else if(!response) return Kick(playerid);
}
return 1;
}
Re: MySQL Login problem.. -
TheArcher - 22.11.2011
store the result on login.
Re: MySQL Login problem.. -
TheBluec0de - 22.11.2011
i added store result on login, but dosent work...
Re: MySQL Login problem.. -
TheArcher - 22.11.2011
The password don't match beacuse when the player tries to log in it doesn't match the real password with the hashed one.
Re: MySQL Login problem.. -
TheBluec0de - 22.11.2011
and how can I fix this?
Re: MySQL Login problem.. -
TheArcher - 22.11.2011
Where did you take SHA1 ? And where did you put it?
Re: MySQL Login problem.. -
JaTochNietDan - 22.11.2011
The contents of "PasswordStringa" are un-clear, why not just use "EscPassword" since you already escaped it? For example in your register snippet:
pawn Код:
mysql_real_escape_string(inputtext, EscPassword);
format(Query, sizeof(Query), "INSERT INTO Utenti (Nome, Password, Ip, Soldi, Punteggio, Uccisioni, Morti) VALUES('%s', SHA1('%s'), '%s', 0, 0, 0, 0)", GetPlayerNomeEx(playerid), EscPassword, GetPlayerIpEx(playerid));
Note: In order for this to work you need to try with a new account
Re: MySQL Login problem.. -
TheBluec0de - 22.11.2011
OK, i have changed "PasswordStringa" in EscPassword, and i have tested in new ACCOUNT, but dosent work....
post the code:
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOGO_REGISTRAZIONE)
{
if(response)
{
if(!strlen(inputtext) || strlen(inputtext) > 10)
{
format(Stringa, sizeof(Stringa), "Inserisci una password tra 1-10 caratteri \nBenvenuto %s nel server Italian Las Venturas!\n\n Il tuo account non risulta registrato.\nRegistra un account inserendo la password qui sotto:", GetPlayerNomeEx(playerid));
ShowPlayerDialog(playerid, DIALOGO_REGISTRAZIONE, DIALOG_STYLE_PASSWORD, "Registrazione", Stringa, "Registra", "Cancella");
}
else
{
mysql_real_escape_string(inputtext, EscPassword);
format(Query, sizeof(Query), "INSERT INTO Utenti (Nome, Password, Ip, Soldi, Punteggio, Uccisioni, Morti) VALUES('%s', SHA1('%s'), '%s', 0, 0, 0, 0)", GetPlayerNomeEx(playerid), EscPassword, GetPlayerIpEx(playerid));
mysql_query(Query);
SendClientMessage(playerid, -1, "SERVER: Registrazione effettuata");
Registrato[playerid] = 1;
}
}
else if(!response) return Kick(playerid);
}
if(dialogid == DIALOGO_ACCESSO)
{
if(response)
{
mysql_real_escape_string(inputtext, EscPassword);
format(Query, sizeof(Query), "SELECT * FROM `Utenti` WHERE `Nome` = '%s' AND `Password` = SHA1('%s')", GetPlayerNomeEx(playerid), EscPassword);
mysql_query(Query);
mysql_store_result();
if(!mysql_num_rows())
{
UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI]++;
if(UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI] == MAX_ACC_FALLITI)
{
SendClientMessage(playerid, -1, "SERVER: Hai superato il limite massimo di tentativi per accedere. Sei stato kickato.");
Kick(playerid);
}
format(Stringa, sizeof(Stringa), "Tentativo accesso %d/%d. A %d tentativi verrai kickato \nBentornato %s nel server Italian Las Venturas!\n\n Il tuo account risulta registrato.\nInserisci la password per accedere:", UtenteInfo[playerid][STATO_UTENTE_ACCFALLITI], MAX_ACC_FALLITI, MAX_ACC_FALLITI, GetPlayerNomeEx(playerid));
ShowPlayerDialog(playerid, DIALOGO_ACCESSO, DIALOG_STYLE_PASSWORD, "Accesso", Stringa, "Accedi", "Cancella");
}
else
{
new MySQLStringa[20];
while (mysql_retrieve_row())
{
mysql_fetch_field_row(MySQLStringa, "Soldi"); UtenteInfo[playerid][STATO_UTENTE_SOLDI] = strval(MySQLStringa);
mysql_fetch_field_row(MySQLStringa, "Punteggio"); SetPlayerScore(playerid, strval(MySQLStringa));
mysql_fetch_field_row(MySQLStringa, "Uccisioni"); UtenteInfo[playerid][STATO_UTENTE_UCCISIONI] = strval(MySQLStringa);
mysql_fetch_field_row(MySQLStringa, "Morti"); UtenteInfo[playerid][STATO_UTENTE_MORTI] = strval(MySQLStringa);
}
mysql_free_result();
SendClientMessage(playerid, -1, "SERVER: Accesso effettuato");
Accesso[playerid] = 1;
}
mysql_free_result();
}
else if(!response) return Kick(playerid);
}
return 1;
}