/Changename command & /Changepassword
#1

Hello guys i coded a /changename command it works good and change my name ingame and in userpath but the problem is when i try to login it says wrong password this is my code:

PHP код:
CMD:changename(playeridparams[])
{
    new 
idnewname[10], oldname[10], string[128];
    if(
isnull(params)) return SendClientMessage(playerid, -1"Changename [NewName]");
    if(
sscanf(params,"s[10]"newname)) return SendClientMessage(playerid, -"/Changename [NewName]");
    if(
strlen(params) < 4) return SendClientMessage(playerid,-1,"Name shoulkd not be less than 4 characters.");
    if(
strlen(params) > 10) return SendClientMessage(playerid,-1,"Name must be 10 characters max.");
    
GetPlayerName(playeridoldnamesizeof(oldname));
    new 
file[64];
    
format(filesizeof(file), "/Users/%s.ini"newname);
    if (
fexist(file)) return SendClientMessage(playerid, -1"The name you entered is already being used by another player!");
    
fremove(UserPath(id));
    
SetPlayerName(id,newname);
    
format(stringsizeof(string), "%s Name changed to (%s)."oldnamenewname);
    
SendClientMessageToAll( -1,string);
    
Kick(id);
    return 
1;

And here is my useracc informations:

before change name
PHP код:
Password 158794218
Cash 
0
AdminLevel 
0
Kills 
0
Deaths 
0
Score 
11
Minutes 
13
Hours 
5
Seconds 

after changename
PHP код:
Cash 0
AdminLevel 
0
Kills 
0
Deaths 
0
Score 
11
Minutes 
13
Hours 
5
Seconds 

i also have another request i want a /changepassword command i know its pretty same as /changename so i am sure it wont be hard for you guys

PS my password is hashed and i use this system https://sampforum.blast.hk/showthread.php?tid=273088

thanks in advance
Reply
#2

The problem is that you are not saving the player's password back again to the file, if you are using Y_INI you could:

PHP код:
CMD:changename(playeridparams[])
{
    new 
idnewname[10], oldname[10], string[128];
    if(
isnull(params)) return SendClientMessage(playerid, -1"Changename [NewName]");
    if(
sscanf(params,"s[10]"newname)) return SendClientMessage(playerid, -"/Changename [NewName]");
    if(
strlen(params) < 4) return SendClientMessage(playerid,-1,"Name shoulkd not be less than 4 characters.");
    if(
strlen(params) > 10) return SendClientMessage(playerid,-1,"Name must be 10 characters max.");
    
GetPlayerName(playeridoldnamesizeof(oldname));
    new 
file[64];
    
format(filesizeof(file), "/Users/%s.ini"newname);
    if (
fexist(file)) return SendClientMessage(playerid, -1"The name you entered is already being used by another player!");
    
fremove(UserPath(id));
    
SetPlayerName(id,newname);
    new 
INI:pfile INI_Open(file);
    
INI_WriteInt(pfile"Password"PlayerInfo[playerid][pPassword]);
    
INI_Close(pfile);
    
format(stringsizeof(string), "%s Name changed to (%s)."oldnamenewname);
    
SendClientMessageToAll( -1,string);
    
Kick(id);
    return 
1;

NOTE: The PlayerInfo[playerid][pPassword] is an example, you must put the variable where you store the player's password.
Reply
#3

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
The problem is that you are not saving the player's password back again to the file, if you are using Y_INI you could:

PHP код:
CMD:changename(playeridparams[])
{
    new 
idnewname[10], oldname[10], string[128];
    if(
isnull(params)) return SendClientMessage(playerid, -1"Changename [NewName]");
    if(
sscanf(params,"s[10]"newname)) return SendClientMessage(playerid, -"/Changename [NewName]");
    if(
strlen(params) < 4) return SendClientMessage(playerid,-1,"Name shoulkd not be less than 4 characters.");
    if(
strlen(params) > 10) return SendClientMessage(playerid,-1,"Name must be 10 characters max.");
    
GetPlayerName(playeridoldnamesizeof(oldname));
    new 
file[64];
    
format(filesizeof(file), "/Users/%s.ini"newname);
    if (
fexist(file)) return SendClientMessage(playerid, -1"The name you entered is already being used by another player!");
    
fremove(UserPath(id));
    
SetPlayerName(id,newname);
    new 
INI:pfile INI_Open(file);
    
INI_WriteInt(pfile"Password"PlayerInfo[playerid][pPassword]);
    
INI_Close(pfile);
    
format(stringsizeof(string), "%s Name changed to (%s)."oldnamenewname);
    
SendClientMessageToAll( -1,string);
    
Kick(id);
    return 
1;

NOTE: The PlayerInfo[playerid][pPassword] is an example, you must put the variable where you store the player's password.
Thank you very much its working well now

Waiting for password change if you can explain to me
Reply
#4

PHP код:
#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf>
#define HASH // Put '//' in front of define if you don't want a hash for your password ..
// udb_hash can be modified with your hasher if you have another one (if you don't have one you need to put '//' in front of define)
#define TAG // Put '//' if you don't use a tag where you save password.
 #if defined HASH
udb_hash(buf[]) // By darcoblue | Password hasher .
{
    new 
s1=1s2;
    for(new 
nn<strlen(buf); n++) { s1 = (s1 buf[n]) % 65521s2 = (s2 s1)     % 65521; }
    return (
s2 << 16) + s1;
}
 
#endif
CMD:changepassword(playeridparams[])
{
    new 
pPass[16], pName[32]; // some news ..
    
GetPlayerName(playeridpNamesizeof(pName)); // get the player name (who typed)
    
    
if(sscanf(params,"s"pPass)) return SendClientMessage(playerid, -"/changepassword [NewPassword]"); // Return a message if parameters are null ..
    
if(strlen(pPass) < || strlen(pPass) > 15) return SendClientMessage(playerid, -1"Your new password need to be between 3 and 15 characters.");
    if(
strfind(pPass"/") != -|| strfind(pPass"\\") != -|| strfind(pPass":") != -|| strfind(pPass"*") != -||
    
strfind(pPass"?") != -|| strfind(pPass"\"") != -|| strfind(pPass"<") != -|| strfind(pPass">") != -||
    
strfind(pPass"|") != -|| strfind(pPass"@")) return SendClientMessage(playerid, -1"INVALID CHARACTERS: '/' '\' ':' '?' '\' '<' '>' '*' '|' '@'"); // Characters black list .
    
new fPath[64]; // create a string
    
format(fPathsizeof(fPath), "/Users/%s.ini"pName); // Format the fPath string array
    
new INI:File INI_Open(fPath); // a new initialiser for our INI_Open ..
    
 #if defined TAG
    
INI_SetTag(File"data"); // We set tag 'data'
 #endif
    
 #if defined HASH
    
INI_WriteInt(File"Password"udb_hash(pPass)); // Write our hashed password
 #else
    
INI_WriteString(File"Password"pPass); // Write our string password
 #endif
    
INI_Close(File); // Close the file
    
    
SendClientMessage(playerid, -1"You changed your password , at next login you need to type new password.");
    return 
1;

Reply
#5

Quote:
Originally Posted by Mariciuc223
Посмотреть сообщение
[php]udb_hash(buf[]) // By darcoblue | Password hasher .
{
new s1=1, s2;
for(new n; n<strlen(buf); n++) { s1 = (s1 + buf[n]) % 65521; s2 = (s2 + s1) % 65521; }
return (s2 << 16) + s1;
}
This is BAD BAD BAD.

Before officially releasing your server, i strongly recommend not using this insecure "hash" if i can call it, use the builtin SHA256_PassHash or get Whirlpool.
Reply
#6

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
This is BAD BAD BAD.

Before officially releasing your server, i strongly recommend not using this insecure "hash" if i can call it, use the builtin SHA256_PassHash or get Whirlpool.
That it's his hasher ... i made it on his hasher ...
Reply
#7

Quote:
Originally Posted by Mariciuc223
Посмотреть сообщение
PHP код:
#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf>
#define HASH // Put '//' in front of define if you don't want a hash for your password ..
// udb_hash can be modified with your hasher if you have another one (if you don't have one you need to put '//' in front of define)
#define TAG // Put '//' if you don't use a tag where you save password.
 #if defined HASH
udb_hash(buf[]) // By darcoblue | Password hasher .
{
    new 
s1=1s2;
    for(new 
nn<strlen(buf); n++) { s1 = (s1 buf[n]) % 65521s2 = (s2 s1)     % 65521; }
    return (
s2 << 16) + s1;
}
 
#endif
CMD:changepassword(playeridparams[])
{
    new 
pPass[16], pName[32]; // some news ..
    
GetPlayerName(playeridpNamesizeof(pName)); // get the player name (who typed)
    
    
if(sscanf(params,"s"pPass)) return SendClientMessage(playerid, -"/changepassword [NewPassword]"); // Return a message if parameters are null ..
    
if(strlen(pPass) < || strlen(pPass) > 15) return SendClientMessage(playerid, -1"Your new password need to be between 3 and 15 characters.");
    if(
strfind(pPass"/") != -|| strfind(pPass"\\") != -|| strfind(pPass":") != -|| strfind(pPass"*") != -||
    
strfind(pPass"?") != -|| strfind(pPass"\"") != -|| strfind(pPass"<") != -|| strfind(pPass">") != -||
    
strfind(pPass"|") != -|| strfind(pPass"@")) return SendClientMessage(playerid, -1"INVALID CHARACTERS: '/' '\' ':' '?' '\' '<' '>' '*' '|' '@'"); // Characters black list .
    
new fPath[64]; // create a string
    
format(fPathsizeof(fPath), "/Users/%s.ini"pName); // Format the fPath string array
    
new INI:File INI_Open(fPath); // a new initialiser for our INI_Open ..
    
 #if defined TAG
    
INI_SetTag(File"data"); // We set tag 'data'
 #endif
    
 #if defined HASH
    
INI_WriteInt(File"Password"udb_hash(pPass)); // Write our hashed password
 #else
    
INI_WriteString(File"Password"pPass); // Write our string password
 #endif
    
INI_Close(File); // Close the file
    
    
SendClientMessage(playerid, -1"You changed your password , at next login you need to type new password.");
    return 
1;

hello thanks for helping but there is a problem with your code it doesnt save password in userfile it only write the title like this

Quote:

Password =

Reply
#8

Код:
#include <a_samp>
#include <zcmd>
#include <YSI\y_ini>
#include <sscanf>

udb_hash(buf[]) // By darcoblue | Password hasher .
{
    new s1=1, s2;
    for(new n; n<strlen(buf); n++) { s1 = (s1 + buf[n]) % 65521; s2 = (s2 + s1)     % 65521; }
    return (s2 << 16) + s1;
}

CMD:changepassword(playerid, params[])
{
    new pPass[16], pName[32]; // some news ..
    GetPlayerName(playerid, pName, sizeof(pName)); // get the player name (who typed)

    if(sscanf(params,"s", pPass)) return SendClientMessage(playerid, -1 , "/changepassword [NewPassword]"); // Return a message if parameters are null ..
    if(strlen(pPass) < 3 || strlen(pPass) > 15) return SendClientMessage(playerid, -1, "Your new password need to be between 3 and 15 characters.");
    if(strfind(pPass, "/") != -1 || strfind(pPass, "\\") != -1 || strfind(pPass, ":") != -1 || strfind(pPass, "*") != -1 ||
    strfind(pPass, "?") != -1 || strfind(pPass, "\"") != -1 || strfind(pPass, "<") != -1 || strfind(pPass, ">") != -1 ||
    strfind(pPass, "|") != -1 || strfind(pPass, "@")) return SendClientMessage(playerid, -1, "INVALID CHARACTERS: '/' '\' ':' '?' '\' '<' '>' '*' '|' '@'"); // Characters black list .

    new fPath[64]; // create a string
    format(fPath, sizeof(fPath), "/Users/%s.ini", pName); // Format the fPath string array

    new INI:File = INI_Open(fPath); // a new initialiser for our INI_Open ..
    INI_SetTag(File, "data"); // We set tag 'data'
    INI_WriteInt(File, "Password", udb_hash(pPass)); // Write our hashed password
    INI_Close(File); // Close the file

    SendClientMessage(playerid, -1, "You changed your password , at next login you need to type new password.");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)