Password Reset
#1

I'm having problem with Login/Register System. If a Player Register and then relog then he will be able to login. But When I Restart my Server then When a Player Connects then His Hashed Password Get Reset in his .ini saved file. What can be the problem?

PHP Code:
public OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid)))
    {
        
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
        new 
str[400];
        
format(str,sizeof(str),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n",PlayerName(playerid));
          
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"{0081FF}Login Panel",str,"Login","Quit");
        
SendClientMessage(playerid,yellow,"Welcome Back, Please Login To Access Your Account");
    }
    else
    {
        new 
str1[400];
        
format(str1,sizeof(str1),"{FFFFFF}Your Account Name \"%s\" is not registered. \n\nPlease register your password to save your status\n\nEnter the password Below:",PlayerName(playerid));
        
SendClientMessage(playerid,yellow,"Please Register Your Account");
         
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT,"{0081FF}Registering Panel",str1,"Register","Quit");
    }
    
PlayerPlaySound(playerid1027 0.00.010.0);
    
CamMove[playerid]=true;
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    
SaveUser(playerid);
    
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
DIALOG_REGISTER:
        {
            if (!
response) return Kick(playerid);
            if(
response)
            {
                if(
strlen(inputtext)<6)
                {    
                new 
str1[400];
                
format(str1,sizeof(str1),"{FFFFFF}Your Account Name \"%s\" is not registered. \n\nPlease register your password to save your status\n\nEnter the password Below:\n{B71800}Password must be 6 characters long\n\n",PlayerName(playerid));
                
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT,"{007BBE}Registering Panel",str1,"Register","Quit");
            
                }
                new 
hashpass[129]; 
                
WP_Hash(hashpass,sizeof(hashpass),inputtext);
                
format(Player[playerid][password],129,hashpass);
                
Player[playerid][cash]=0;
                
Player[playerid][score]=0;
                
Player[playerid][kills]=0;
                
Player[playerid][deaths]=0;
                
Player[playerid][ADMIN]=0;
                
Player[playerid][VIP]=0;
                
Player[playerid][TP]=0;
                
Player[playerid][FBI]=0;
                
Player[playerid][terrorist]=0;
                
SaveUser(playerid);
            }
        }
        case 
DIALOG_LOGIN:
        {
            if (!
response) return Kick(playerid);
            if(
response)
            {
                if(!
strlen(inputtext))
                {
                    new 
str3[400];
                    
format(str3,sizeof(str3),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n",PlayerName(playerid));
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"{007BBE}Login Panel",str3,"Login","Quit");
                }
                new 
hashpass[129]; 
                
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
                
WP_Hash(hashpass,sizeof(hashpass),inputtext);
                if(!
strcmp(hashpass,Player[playerid][password],false))
                {
                    
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
                    
GivePlayerMoney(playeridPlayer[playerid][cash]);
                    
SetPlayerScore(playerid,Player[playerid][score]);
                }
                else
                {
                    new 
str3[400];
                    
format(str3,sizeof(str3),"{FFFFFF}This Account Name \"%s\" is registered in our server.\n\nIf You are the owner of the account then please Login\n\n{B71800}Password Incorrect",PlayerName(playerid));
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"{007BBE}Login Panel",str3,"Login","Quit");
                    }
                return 
1;
            }
        }
    }
    return 
1;
}
stock UserPath(playerid)
{
    new 
string[128],playername[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,playername,sizeof(playername));
    
format(string,sizeof(string),PATH,playername);
    return 
string;
}
forward LoadUser_data(playerid,name[],value[]);
public 
LoadUser_data(playerid,name[],value[])
{
    
INI_String("Password"Player[playerid][password],129);
    
INI_Int("Cash",Player[playerid][cash]);
    
INI_Int("Score",Player[playerid][score]);
    
INI_Int("Kills",Player[playerid][kills]);
    
INI_Int("Deaths",Player[playerid][deaths]);
    
INI_Int("Admin",Player[playerid][ADMIN]);
    
INI_Int("VIP",Player[playerid][VIP]);
    
INI_Int("TP",Player[playerid][TP]);
    
INI_Int("FBI",Player[playerid][FBI]);
    
INI_Int("TERRORIST",Player[playerid][terrorist]);
     return 
1;
}
stock SaveUser(playerid)
{
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_WriteString(File,"Password",Player[playerid][password]);
    
INI_WriteInt(File,"Cash",Player[playerid][cash]);
    
INI_WriteInt(File,"Score",Player[playerid][score]);
    
INI_WriteInt(File,"Kills",Player[playerid][kills]);
    
INI_WriteInt(File,"Deaths",Player[playerid][deaths]);
    
INI_WriteInt(File,"Admin",Player[playerid][ADMIN]);
    
INI_WriteInt(File,"VIP",Player[playerid][VIP]);
    
INI_WriteInt(File,"TP",Player[playerid][TP]);
    
INI_WriteInt(File,"FBI",Player[playerid][FBI]);
    
INI_WriteInt(File,"TERRORIST",Player[playerid][terrorist]);
    
INI_Close(File);
}
stock PlayerName(playerid)
{
new 
name[128];
GetPlayerName(playerid,name,sizeof(name));
return 
name;

Reply
#2

Code:
stock udb_hash(buf[]) { //Credits to Dracoblue
	new length=strlen(buf);
	new s1 = 1;
	new s2 = 0;
	new n;
	for (n=0; n<length; n++)
	{
	   s1 = (s1 + buf[n]) % 65521;
	   s2 = (s2 + s1)     % 65521;
	}
	return (s2 << 16) + s1;
}
I use that hasher (You need to save / load password like a integer if you use that)
Reply
#3

Hello!

You shouldn't restart the server if players are online.
First you should kick the player and then if there are 0 players online restart the server.
Reply
#4

Nope.. thats not working
Reply
#5

Quote:
Originally Posted by Mariciuc223
View Post
Code:
stock udb_hash(buf[]) { //Credits to Dracoblue
	new length=strlen(buf);
	new s1 = 1;
	new s2 = 0;
	new n;
	for (n=0; n<length; n++)
	{
	   s1 = (s1 + buf[n]) % 65521;
	   s2 = (s2 + s1)     % 65521;
	}
	return (s2 << 16) + s1;
}
I use that hasher (You need to save / load password like a integer if you use that)
Hell NO! If you are willing to get your password cracked in 5 seconds, then use udb.

Also, im not familiar with YSI but afaik you need to use INI_SetTag while writing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)