[HELP] changepass yini
#1

It actually changes the hash in password but i can't login with new password,i can log only with old pass

Код:
CMD:changepass(playerid,params[])
{
    new newstring[128];
    new newpass[129];
    if(PInfo[playerid][Logged] == 0)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be logged in first.");
    if(sscanf(params,"s[128]",newpass))
	return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /changepass [new pass]");
 	format(newstring, sizeof(newstring), "You have successfully changed your password to %s",newpass);
    SendClientMessage(playerid,COLOR_PALEGREEN,newstring);
	WP_Hash(newpass,sizeof(newpass),newstring);
	new INI:file = INI_Open(Path(playerid));
	PInfo[playerid][Password] = newpass;
	INI_Close(file);
	return 1;
}
Reply
#2

Code it's good, but you don't write in file your's new password:

pawn Код:
CMD:changepass(playerid,params[])
{
    new newstring[128];
    new newpass[129];
    if(PInfo[playerid][Logged] == 0)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be logged in first.");
    if(sscanf(params,"s[128]",newpass))
    return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /changepass [new pass]");
    format(newstring, sizeof(newstring), "You have successfully changed your password to %s",newpass);
    SendClientMessage(playerid,COLOR_PALEGREEN,newstring);
    WP_Hash(newpass,sizeof(newpass),newstring);
        PInfo[playerid][Password] = newpass;
    new INI:file = INI_Open(Path(playerid));
        INI_WriteString(file, "Password", newpass);
    INI_Close(file);
    return 1;
}
You should rename from string that 'Password', I don't know how it's your config file.
But, you should understand.
Reply
#3

this is my config file

i tried your code,now it shows this in my file

Password = 04C730B23159E2FA3B3148B8C3EC784EA8E0D62D11D44E5040 405E24440A554B376A54AAE82625B93C8804BF00666FA748A2 5DC198E30DE6025BE9DC09C3B717
[Player's Data]
Password = 0AA2336AC0A19C46864358E6F39FA9E48C252A705170CF4B7C A4F8A93C55960F93A156BFD81B9FBA286AFBC07E6B982D156D AD03AB250361CB8A503A673DFA13
AdminLevel = 7
Money = 0
Score = 0
Kill = 0
Death = 0
Mute = 0
Jail = 0
CMDMuted = 0
Crashed = 0
Crash = 0
Reply
#4

That one should work:

Код:
CMD:changepass(playerid,params[])
{
    new newstring[128];
    new newpass[129];
    if(PInfo[playerid][Logged] == 0)
    return SendClientMessage(playerid,STEALTH_BLUE,"You need to be logged in first.");
    if(sscanf(params,"s[128]",newpass))
	return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /changepass [new pass]");
 	format(newstring, sizeof(newstring), "You have successfully changed your password to %s",newpass);
    SendClientMessage(playerid,COLOR_PALEGREEN,newstring);
	WP_Hash(newpass,sizeof(newpass),newstring);
        PInfo[playerid][Password] = newpass;
        INI_ParseFile(Path(playerid), "ChangePass", .bExtra = true, .extra = newpass);
	return 1;
}

forward ChangePass(newpass, name[], value[]);
public ChangePass(newpass, name[], value[])
{
     INI_String("Password", newpass);
     return 0;
}
Reply
#5

Not working its gives me errors
Reply
#6

Ok, you almost got it, but you forgot one line, made one mistake, and stubled upon pawn quirk:
pawn Код:
new INI:file = INI_Open(Path(playerid));
strcpy(PInfo[playerid][Password], newpass, 129);
INI_WriteString(file, "Password", newpass);
INI_Close(file);
1. You can't copy strings using =, use strcpy/strcat instead
2. Use WriteString to update ini file
3. You have to pass third argument to strcpy/strcat if you pass some enumerated variable. because pawn can't detect the size of your enum field (notice the 129)
Reply
#7

Quote:
Originally Posted by Nabster
Посмотреть сообщение
Not working its gives me errors
What errors are you getting? Post them please.
Reply
#8

Try this:
pawn Код:
CMD:changepass(playerid,params[])
{
    new newstring[128], newpass[129];
        if(PInfo[playerid][Logged] == 0) return SendClientMessage(playerid,STEALTH_BLUE,"You need to be logged in first.");
        if(sscanf(params,"s[128]",newpass))
    return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /changepass [new pass]");
    format(newstring, sizeof(newstring), "You have successfully changed your password to %s",newpass);
        SendClientMessage(playerid,COLOR_PALEGREEN,newstring);
    WP_Hash(newpass, sizeof(newpass), newstring);
    new INI:file = INI_Open(Path(playerid));
    INI_SetTag(file, "[Player's Data]");
    INI_WriteString(file, "Password", newpass);
    INI_Close(file);
    PInfo[playerid][Password] = newpass;
    return 1;
}
Reply
#9

None of them are working,it doesn't save new password
Reply
#10

INI_WriteString is for writing new values on an INI file. So that is what will be made in the end:

Quote:
Originally Posted by Nabster
Посмотреть сообщение
this is my config file

i tried your code,now it shows this in my file

Password = 04C730B23159E2FA3B3148B8C3EC784EA8E0D62D11D44E5040 405E24440A554B376A54AAE82625B93C8804BF00666FA748A2 5DC198E30DE6025BE9DC09C3B717
[Player's Data]
Password = 0AA2336AC0A19C46864358E6F39FA9E48C252A705170CF4B7C A4F8A93C55960F93A156BFD81B9FBA286AFBC07E6B982D156D AD03AB250361CB8A503A673DFA13
AdminLevel = 7
Money = 0
Score = 0
Kill = 0
Death = 0
Mute = 0
Jail = 0
CMDMuted = 0
Crashed = 0
Crash = 0
And if he uses INI_SetTag it will be made like
Код:
[Player's Data]
Password = 04C730B23159E2FA3B3148B8C3EC784EA8E0D62D11D44E5040405E24440A554B376A54AAE82625B93C8804BF00666FA748A25DC198E30DE6025BE9DC09C3B717
[Player's Data]
Password = 0AA2336AC0A19C46864358E6F39FA9E48C252A705170CF4B7CA4F8A93C55960F93A156BFD81B9FBA286AFBC07E6B982D156DAD03AB250361CB8A503A673DFA13
AdminLevel = 7
Money = 0
Score = 0
Kill = 0
Death = 0
Mute = 0
Jail = 0
CMDMuted = 0
Crashed = 0
Crash = 0
You can either use INI_Load or INI_Parsefile to open a file for reading or editing.
Edited it a little bit, it gave me no errors while compiling. Try that and don't use INI_WriteString as the others say.

Код:
CMD:changepass(playerid,params[])
{
     new newstring[64], hashpass[129], newpass[32];
     if(PInfo[playerid][Logged] == 0)
          return SendClientMessage(playerid,STEALTH_BLUE,"You need to be logged in first.");
     if(sscanf(params,"s[32]",newpass))
          return SendClientMessage(playerid,STEALTH_BLUE,"USAGE: /changepass [new pass]");
     format(newstring, sizeof(newstring), "You have successfully changed your password to %s",newpass);
     SendClientMessage(playerid,COLOR_PALEGREEN,newstring);
     WP_Hash(hashpass,sizeof(hashpass),newpass);
     format(PInfo[playerid][Password], 129, "%s", hashpass);
     INI_ParseFile(Path(playerid), "ChangePass", .bExtra = true, .extra = playerid);
     return 1;
}

forward ChangePass(playerid, name[], value[]);
public ChangePass(playerid, name[], value[])
{
     INI_String("Password", PInfo[playerid][Password], 129);
     return 0;
}
Also make sure that in your enumerator the size of Password is already set
Код:
enum Example {
     Password[129]
}

new PInfo[MAX_PLAYERS][Example];
Something like that.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)