20.07.2013, 13:47
So I'm trying to hash player passwords with SQLite but it doesn't create the players account. Here is the code:
pawn Код:
new
Query[ 256 ],
DBResult: Result,
name[ MAX_PLAYER_NAME ],
ip[ 16 ]
;
GetPlayerName(playerid, name, sizeof(name));
GetPlayerIp(playerid, ip, sizeof(ip));
if(dialogid == 1)
{
if(response)
{
new hashpass [129];
WP_Hash (hashpass, sizeof (hashpass), inputtext);
format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s' COLLATE NOCASE AND `PASSWORD` = '%s'", DB_Escape(name), DB_Escape(hashpass));
Result = db_query(Database, Query);
if(db_num_rows(Result))
{
new Field[ 20 ];
db_get_field_assoc(Result, "SCORE", Field, 30);
SetPlayerScore(playerid, strval(Field));
db_get_field_assoc(Result, "CASH", Field, 30);
GivePlayerMoney(playerid, strval(Field));
db_get_field_assoc(Result, "ADMINLEVEL", Field, 30);
SInfo[playerid][pAdmin] = strval(Field);
db_get_field_assoc(Result, "BANNED", Field, 30);
SInfo[playerid][pBan] = strval(Field);
db_get_field_assoc(Result, "REGULAR", Field, 30);
SInfo[playerid][pRegular] = strval(Field);
db_get_field_assoc(Result, "KILLS", Field, 30);
SInfo[playerid][pKills] = strval(Field);
db_get_field_assoc(Result, "DEATHS", Field, 30);
SInfo[playerid][pDeaths] = strval(Field);
SendClientMessage(playerid, -1, "You have "COL_GREEN"successfully{FFFFFF} logged in! ");
}
else
{
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're registered\n\nPlease log in by inputting your password. ", name, playerid);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "{FFFFFF}Register", Query, "Login", "Leave");
SendClientMessage(playerid, -1, ""COL_RED"Wrong{FFFFFF} password, try again!");
}
db_free_result(Result);
}
else return Kick(playerid);
}
if(dialogid == 0)
{
if(response)
{
new hashpass [129];
WP_Hash (hashpass, sizeof (hashpass), inputtext);
if(strlen(inputtext) > 24 || strlen(inputtext) < 3)
{
format(Query, sizeof(Query), "{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF} to the server, you're "COL_RED"not{FFFFFF} registered\n\nPlease log in by inputting your password. ", name, playerid);
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "{FFFFFF}Register", Query, "Register", "Leave");
SendClientMessage(playerid, -1, "Your password length must be from 3 - 24 characters!");
}
else
{
format(Query, sizeof(Query), "INSERT INTO `USERS` (`NAME`, `PASSWORD`, `IP`, `SCORE`, `CASH`, `ADMINLEVEL`, `KILLS`, `DEATHS`, `REGULAR`) VALUES('%s','%s','%s', '0', '500', '0','0','0','0')", DB_Escape(name), DB_Escape(hashpass), DB_Escape(ip));
db_query(Database, Query);
GivePlayerMoney(playerid, 500);
SetPlayerScore(playerid, 0);
SendClientMessage(playerid, -1, "You have "COL_GREEN"successfully{FFFFFF} registered! You have been automatically logged in!");
}
}
else return Kick(playerid);
}
return 0;
}