15.03.2012, 18:51
Hello dear samp forum members. I have one problem...Today i convert my old saving system to y_ini and whirpool hassh password...problem is when i register one user, i go out and i go to test password...I can login with any password what i enter...Pls help..here is some code of load user,onplayerconnect,login and register dialogs:
first at all some definitions:
loaduserdata:
onplayerconnect:
dialogs for login and register:
onplayerlogin:
and on playerregister:
and this is how y_ini save files on register:
first at all some definitions:
Код:
native WP_Hash(buffer[], len, const str[]); //native function for hashing passwords forward LoadUserData(playerid, name[], value[]); //forwarding function LoadUserData #define INI_Exists(%0) fexist(%0) #define DIALOG_REGISTER 13245 //define for dialog id #define DIALOG_LOGIN 13246 //define for dialog id #define USER_FILE "Users/%s.ini"
Код:
public LoadUserData(playerid, name[], value[]) //new function with playerid, player name and value { //opening barrel INI_String("Key", PlayerInfo[playerid][pKey], 129); //loading player password, Whirlpool hash 128 characters + NULL INI_Int("Money",PlayerInfo[playerid][pCash]); INI_Int("AdminLevel",PlayerInfo[playerid][pAdmin]); INI_Int("Level",PlayerInfo[playerid][pLevel]); INI_Int("Locked",PlayerInfo[playerid][pLocked]); return 1; //returning true } //closing barrel
Код:
new naslov2[256], text[128], strText[104]; //some new variables for title, text in dialog and text that player type format(strText, 35, USER_FILE, GetName(playerid)); //formating our file, path where it will be saved and getting player name if(!INI_Exists(strText)) //if ini doesn't exist player will get this: { //opening barrel format(naslov2, sizeof(naslov2), ""COL_BLUE"Dobrodosli na Weber,"COL_WHITE" \n\n%s!", GetName(playerid)); //formating our title, some text, colors balabalbal format(text, sizeof(text), ""COL_WHITE"______________________________\n\n"COL_BLUE"Ime"COL_WHITE" %s"COL_BLUE" nije registrirano!\n\nMolimo da se registrirate!", GetName(playerid)); //formating our text ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, naslov2, text, "Register", "Exit"); //showing player dialog for registering } else //but if exists player will get this { //opening barrel format(naslov2, sizeof(naslov2), ""COL_GREEN"Dobrodosli na Weber,"COL_WHITE" \n\n%s!", GetName(playerid)); //formating our title, some text, colors... format(text, sizeof(text),""COL_WHITE"______________________________\n\n"COL_GREEN"Ime"COL_WHITE" %s"COL_GREEN" je registrirano!\n\nMozes se logirati!", GetName(playerid)); //formating our text in dialog ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, naslov2, text, "Login", "Exit"); //showing player dialog for login SetPVarInt(playerid, "Joinned", 1); } //closing barrel
Код:
switch(dialogid) //switching to dialogid { //opening barrel case DIALOG_REGISTER: //for registering { //opening barrel if(response) { //opening barrel new strText[179], naslov2[128]; //some variables for text that player type and title if(strlen(inputtext) >= 4 && strlen(inputtext) <= 35) //if player type password more than 4 and less than 35 characters he will get this { //opening barrel OnPlayerRegister(playerid, inputtext); //Loading stats new regstring[128]; new regname[64]; GetPlayerName(playerid,regname,sizeof(regname)); format(regstring,sizeof(regstring),"%s. Vi ste se uspjesno registrovali!",regname); ShowPlayerDialog(playerid,12333,DIALOG_STYLE_MSGBOX,"Registracija",regstring,"Uredu",""); format(strText, 179, "Registrirani ste pod imenom {FFFFFF}'%s' {FFFF00}vaљ password je {FFFFFF}'%s'{FFFF00}, ne zaboravite podatke!", GetName(playerid), inputtext); //formating our text SendClientMessage(playerid, COLOR_YELLOW, strText); //send client message SetTimerEx("uspjesnoregister", 5000, false, "i", playerid); } //closing barrel else //but if he type less than 4 or more than 35 characters he will get this { //opening barrel format(naslov2, sizeof(naslov2), ""COL_BLUE"Dobrodosli na Weber,"COL_WHITE" \n\n%s!", GetName(playerid)); //formating our title, some text, colors balabalbal format(strText, 179, ""COL_WHITE"______________________________\n\n"COL_BLUE"Ime"COL_WHITE" %s"COL_BLUE" nije registrirano!\n\n{F81414}Lozinka mora biti izmedju 4 i 35 slova/brojeva duzine!", GetName(playerid)); //formating our text ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, naslov2, strText, "Register", "Exit"); //showing player dialog for registering } //closing barrel } //closing barrel else Kick(playerid); //if he choose Exit button it , server will kick him, this is response :D } //closing barrel case DIALOG_LOGIN: //for loging { //opening barrel if(response) { //opening barrel new strText[179], naslov2[128]; //some variables for text that player type and title if(strlen(inputtext) >= 4 && strlen(inputtext) <= 35) //if player type password more than 4 or less than 35 characters he will get this { //opening barrel OnPlayerLogin(playerid, inputtext); //loading stats } //closing barrel else //but if he type less than 4 or more than 35 characters he will get this { //opening barrel format(naslov2, sizeof(naslov2), ""COL_GREEN"Dobrodosli na Weber,"COL_WHITE" \n\n%s!", GetName(playerid)); //formating our title, some text, colors... format(strText, 179, ""COL_WHITE"______________________________\n\n"COL_GREEN"Hey"COL_WHITE" %s"COL_GREEN" upisali ste krivi password.\n"COL_WHITE"Upisite ispravan password!", GetName(playerid)); //formating our text in dialog ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, naslov2, strText, "Login", "Exit"); //showing player dialog for login SetPVarInt(playerid, "Joinned", 1); } return 1; } } }
Код:
new hashPassword[129], //variable for hashing password uFile[35]; //variable for file format(uFile, 35, USER_FILE, GetName(playerid)); //formating file, path where it will be saved and getting player name INI_ParseFile(uFile, "LoadUserData", .bExtra = true, .extra = playerid); //I don't now what is this xD WP_Hash(hashPassword, 129, password); //hashing password, Whirlpool hash 128 characters + NULL if(strcmp(PlayerInfo[playerid][pKey], hashPassword, true)) //if player type true (Right) password he will be logged in { //opening barrel SafeGivePlayerMoney(playerid,PlayerInfo[playerid][pCash]); SetPVarInt(playerid, "Logged", 1); //setting PVar that palyer is logged in } //closing barrel
Код:
public OnPlayerRegister(playerid, password[]) { if(IsPlayerConnected(playerid)) { new hashPassword[129], //variable for hashing password uFile[35]; //variable for file format(uFile, 35, USER_FILE, GetName(playerid)); //formating our file, where files saves and getting player name new INI:playerFile = INI_Open(uFile); //creating new ini file called playerFile and opening it WP_Hash(hashPassword, 129, password); //hashing password, Whirlpool hash 128 characters + NULL INI_SetTag(playerFile,"data"); INI_WriteString(playerFile,"Key",hashPassword); INI_WriteInt(playerFile,"Money",500); INI_WriteInt(playerFile,"AdminLevel",0); INI_WriteInt(playerFile,"Level",0); INI_WriteInt(playerFile,"Locked",0); INI_Close(playerFile); SetPVarInt(playerid, "Registered", 1); //setting PVar that player is registered SetPVarInt(playerid, "Logged", 1); //setting PVar that player is logged } return 1; }
Код:
[data] Key = 4E0658D00F47D86D19A0E792E4BB94B16DB2E902D307DA5637F57CF60E7A174CB4BB6D7095621745B2065DF0C87B77AF69F5D0FBD63359AD3CC6B72F076C3E1E Money = 4500 AdminLevel = 0 Level = 0 Locked = 0