Login/register problem (mysql)
#1

pawn Код:
#define THREAD_LoadPlayerLogin (5)
#define THREAD_CompleteLoadPlayer (6)
#define THREAD_CreatePlayer (7)
#define THREAD_CreatedPlayer (8)
#define THREAD_ignoreCallback (1)
pawn Код:
public OnPlayerConnect(playerid)
{
    new sql[512];
    //mysql_real_escape_string(PlayerName(playerid), sql, mysqlCon1);
    format(sql, sizeof sql,"SELECT LastPasswordChange, Password, Banned, UID FROM users WHERE username LIKE '%s' LIMIT 1", PlayerName(playerid));
    mysql_function_query(mysqlCon1, sql, true, "onThreadLoadPlayerLogin", "d", playerid);
    return 1;
}
pawn Код:
forward onThreadLoadPlayerLogin(playerid);
public onThreadLoadPlayerLogin(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        new rows, fields;
        cache_get_data(rows, fields);
        if(rows != 1)
        {
            ShowPlayerDialog(playerid, DIALOG_REG, DIALOG_STYLE_PASSWORD,"Welcome","Type your password below to register a new account","Register","Quit");
        }
        else
        {
            new temp[64];
            cache_get_row(0,2, temp); //Get player banned state
            if(strval(temp) == 0)
            {
                cache_get_row(0,0, temp);
                PlayerInfo[playerid][passGenTime] = strval(temp);
                cache_get_row(0,3, temp);
                PlayerInfo[playerid][UID] = strval(temp);
                cache_get_row(0,1, Passwords[playerid]);
                ShowPlayerDialog(playerid, DIALOG_LOG, DIALOG_STYLE_PASSWORD,"Welcome","Type your password below to login !","Login","Quit");
            }
            else
            {
                new string[129];
                scm(playerid,c_r,"( ! ) Your account is banned from this server.");
                format(string, sizeof(string), "( ! ) %s has been banned by AC for: ban evading", PlayerName(playerid));
                SendClientMessageToAll(COLOR_RED, string);
                Ban(playerid);
                return 1;
            }
        }
        Welcome(playerid);
        MapIcon(playerid);
    }
    return 1;
}
pawn Код:
case DIALOG_LOG:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                new passHash[129], passHash2[128], bool:updatePassword=false;
                valstr(passHash2,udb_hash(inputtext));
                if(PlayerInfo[playerid][passGenTime] == 0 && strcmp(passHash2, Passwords[playerid], true)==0 )
                {
                    updatePassword = true;
                    PlayerInfo[playerid][passGenTime] = gettime();
                }
                passHash = createPasswordHash(PlayerInfo[playerid][passGenTime],inputtext);
                if(updatePassword || strcmp(passHash, Passwords[playerid], true)==0)
                {
                    scm(playerid,COLOR_GREEN,"( ! ) You have logged in !");
                    new sql[128];
                    if(updatePassword)
                    {
                        format(sql, sizeof sql, "UPDATE users SET passLastUpdate = %d, password = '%s' WHERE UID = %d", PlayerInfo[playerid][passGenTime], passHash,PlayerInfo[playerid][UID]);
                        mysql_query(sql,THREAD_ignoreCallback,playerid, mysqlCon1);
                    }
                    format(sql, sizeof sql, "SELECT key_v, value FROM user_data WHERE UID = %d", PlayerInfo[playerid][UID]);
                    mysql_function_query(mysqlCon1, sql, true, "onTHREAD_CompleteLoadPlayer", "d", playerid);
                }
                else
                {
                    printf("%d",PlayerInfo[playerid][passGenTime]);
                    ShowPlayerDialog(playerid, DIALOG_LOG, DIALOG_STYLE_PASSWORD,"SERVER","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
            return 1;
        }
Everything works good but when I login it always say ''wrong password'' even if it was the correct password.
How would I fix this? If anyone want the register codes, I will put them too.

Thanks for your time.
Reply
#2

Anyone could help me with this?
Reply
#3

Hello!

What is printing if you put in your right password.
PHP код:
case DIALOG_LOG:
        {
            if ( !
response ) return Kick playerid );
            if( 
response )
            {
                new 
passHash[129], passHash2[128], bool:updatePassword=false;
                
valstr(passHash2,udb_hash(inputtext));
                
printf("Passwort: %s | Hash: %s",passHash,Passwords[playerid]);
                if(
PlayerInfo[playerid][passGenTime] == && strcmp(passHash2Passwords[playerid], true)==)
                {
                    
updatePassword true;
                    
PlayerInfo[playerid][passGenTime] = gettime();
                }
                
passHash createPasswordHash(PlayerInfo[playerid][passGenTime],inputtext);
                
printf("passHash: %s",passHash);
                
printf("updatePassword: %d",updatePassword);
                if(
updatePassword || strcmp(passHashPasswords[playerid], true)==0)
                {
                    
scm(playerid,COLOR_GREEN,"( ! ) You have logged in !");
                    new 
sql[128];
                    if(
updatePassword)
                     {
                        
format(sqlsizeof sql"UPDATE users SET passLastUpdate = %d, password = '%s' WHERE UID = %d"PlayerInfo[playerid][passGenTime], passHash,PlayerInfo[playerid][UID]);
                        
mysql_query(sql,THREAD_ignoreCallback,playeridmysqlCon1);
                    }
                    
format(sqlsizeof sql"SELECT key_v, value FROM user_data WHERE UID = %d"PlayerInfo[playerid][UID]);
                    
mysql_function_query(mysqlCon1sqltrue"onTHREAD_CompleteLoadPlayer""d"playerid);
                }
                else
                {
                    
printf("%d",PlayerInfo[playerid][passGenTime]);
                    
ShowPlayerDialog(playeridDIALOG_LOGDIALOG_STYLE_PASSWORD,"SERVER","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 
1;
            }
            return 
1;
        } 
Mencent
Reply
#4

[17:03:05] Passwort: | Hash: 5704A80CDDF26A2BF414EA6E04535D35A8E1E911124A0A623C 7
[17:03:05] passHash: 5704A80CDDF26A2BF414EA6E04535D35A8E1E911124A0A623C 735AEE10E786606528D1D2FCA744EDD6A41A3432F84B9FFDB8 97C7FEC56DE7A0E79198E6941C3C
[17:03:05] updatePassword: 0
[17:03:05] 1428764545

Password: test
I don't know what's wrong.
Reply
#5

Sorry, write it so and send the prints again:
PHP код:
case DIALOG_LOG:
{
    if(!
response)return Kick(playerid);
    new 
passHash[129],passHash2[129],bool:updatePassword[MAX_PLAYERS];
    
valstr(passHash2,udb_hash(inputtext));
    
printf("Passwort: %s | Hash: %s",Passwords[playerid],passHash2);
    if(
PlayerInfo[playerid][passGenTime] == && !strcmp(passHash2,Passwords[playerid],true))
    {
        
updatePassword[playerid] = true;
        
PlayerInfo[playerid][passGenTime] = gettime();
    }
    
passHash createPasswordHash(PlayerInfo[playerid][passGenTime],inputtext);
    
printf("passHash: %s",passhash);
    
printf("updatePassword[playerid]: %d",updatePassword[playerid]);
    if(
updatePassword[playerid] == true && !strcmp(passHash,Passwords[playerid],true))
    {
        
scm(playerid,COLOR_GREEN,"( ! ) You have logged in !");
        new 
sql[128];
        if(
updatePassword[playerid] == true)
        {
            
format(sql,sizeof sql,"UPDATE `users` SET `passLastUpdate`='%i',`password`='%s' WHERE `UID`='%i'",PlayerInfo[playerid][passGenTime],passHash,PlayerInfo[playerid][UID]);
            
mysql_query(sql,THREAD_ignoreCallback,playerid,mysqlCon1);
        }
        
format(sql,sizeof sql,"SELECT `key_v`,`value` FROM `user_data` WHERE `UID`='%i'",PlayerInfo[playerid][UID]);
        
mysql_function_query(mysqlCon1,sq,true,"onTHREAD_CompleteLoadPlayer","d",playerid);
    }
    else
    {
        
printf("%d",PlayerInfo[playerid][passGenTime]);
        
ShowPlayerDialog(playeridDIALOG_LOGDIALOG_STYLE_PASSWORD,"SERVER","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
    }
    return 
1;

Mencent
Reply
#6

PHP код:
(5893) : error 028invalid subscript (not an array or too many subscripts): "updatePassword"
(5893) : warning 215expression has no effect
(5893) : error 001expected token";"but found "]"
(5893) : error 029invalid expressionassumed zero
(5893) : fatal error 107too many error messages on one line 
On this line printf("updatePassword[playerid]: %d",updatePassword[playerid]);

When I remove both of [playerid], it works fine. Why did you add [playerid]?
Reply
#7

Then delete [playerid].

Actually, because it is player-specific.

Mencent
Reply
#8

[22:26:11] Passwort: 3DFBAAA2B2080BD507A7CB81B7B7D454655CB3C3CA3B0D17F3 4 | Hash: 73204161
[22:26:11] passHash: 3DFBAAA2B2080BD507A7CB81B7B7D454655CB3C3CA3B0D17F3 44A98FEB3BC33621A019B849C807D58BD3DA8117B93FFD65B8 D89081CE190E81DF4203DF2A2CB7
[22:26:11] updatePassword: 0
[22:26:11] 1428783931
Reply
#9

Let me show your function "createPasswortHash".

Mencent
Reply
#10

pawn Код:
stock createPasswordHash(const username[],const password[])
{
    new user[129], pass[129], combined[129], final[129],temp[257];
    WP_Hash(user, 129, username);
    WP_Hash(pass, 129, password);
    WP_Hash(combined, 129, combine_2_hashes(user,pass));
    final = combined;
    for(new i = 1; i < 21; i++)
    {
        if(i%2 == 0)
        {
            temp = combine_2_hashes(final, combined);
        }
        else
        {
            temp = combine_2_hashes(final, user);
        }
        WP_Hash(final, 129, temp);
    }
    return final;
}
stock combine_2_hashes(const hash1[], const hash2[])
{
    new combined[257];
    for(new i = 0; i < 128;i++)
    {
            combined[i*2] = hash1[i];

            combined[i*2+1] = hash2[i];
    }
    combined[256] = EOS;
    return combined;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)