Hi guys.
#1

Hi, I have a problem with my Register/Login system, register works fine, but when logging in, even tho I write the good password it says it's wrong.Please help me, here's the code.
Код:
case LoginPassword:
		{
			if(!response) return SCM(playerid, COLOR_LIGHTRED, "* Ai primit kick din cauza ca nu ai raspuns la dialog.") && Kick(playerid);
			if( response )
            {
				new query[100], string[256], hashpass[129];
				WP_Hash(hashpass, sizeof(hashpass), inputtext);
	            if(!strcmp(hashpass, PlayerInfo[playerid][pPassword]))
	            {
	                mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `users` WHERE `Name` = '%e' LIMIT 1", GetName(playerid));
	                mysql_tquery(MySQL, query, "OnAccountLoad", "i", playerid);
	            }
	            else
	            {
	            	PasswordIncercari[playerid]--;
	            	if(PasswordIncercari[playerid] == 0) 
	            	{
		            	SCM(playerid, COLOR_RED,"* Ai primit kick deoarece nu ai scris parola corecta de multiple ori.");
		            	Kick(playerid);
		            	printf("[KICK-PASSWORD] %s has been kicked for entering the wrong password 2 times.", GetName(playerid));
	            	}
	            	format(string, sizeof(string), "* Ai scris o parola gresita, mai ai %d incercari.", PasswordIncercari);
	                SendClientMessage(playerid, COLOR_RED, string);
	                ShowPlayerDialog(playerid, LoginPassword, DIALOG_STYLE_PASSWORD, "Login", "Bine ai revenit!\nTe rugam sa te loghezi:", "Login.", "Quit.");
	            }
	        }
		}
And
Код:
case RegisterPassword:
		{
			if(!response) SCM(playerid, COLOR_LIGHTRED, "* Ai primit kick din cauza ca nu ai raspuns la dialog.") && Kick(playerid);
			if(strlen(inputtext) < 5) 
            { 
                SendClientMessage(playerid, -1, "* Your password must have at least 5 characters."); 
                return ShowPlayerDialog(playerid, RegisterPassword, DIALOG_STYLE_PASSWORD, "Register", "Please fill in your desired password:", "Register", "Quit"); 
            } 
            new query[256];
            new IP[16];
			GetPlayerIp(playerid, IP, sizeof(IP));
			PlayerInfo[playerid][pSkin] = 37;
			WP_Hash(PlayerInfo[playerid][pPassword], 129, inputtext);
			mysql_format(MySQL, query, sizeof(query), "INSERT INTO `users` (`Name`, `Password`, `IP`, `Gender`, `Email`, `Skin`) VALUES ('%s', '%e', '%s', 0, 0, '%d')", GetName(playerid), PlayerInfo[playerid][pPassword], IP, 0, 0, PlayerInfo[playerid][pSkin]); 
            mysql_tquery(MySQL, query, "OnAccountRegister", "i", playerid); 
		}
Thank you in advance
Reply
#2

You might be using strcmp wrong. It can be a very confusing function if you want it to work properly.
I, personally am not a big fan of strcmp.

Best would be to use AND to check for password inside your query.
Also, use num rows instead of comparing a string.

PHP код:
WP_Hash(hashpasssizeof(hashpass), inputtext);
mysql_format(MySQLquerysizeof(query), "SELECT * FROM `users` WHERE `Name` = '%e' AND `Password` = '%e'  LIMIT 1"GetName(playerid), hashpass);
if(
mysql_num_rows(query) != 0)
{
 
// password correct
} else {
 
// wrong password/username

Reply
#3

Thank you I will try this tommorow.
Reply
#4

Here you go buddy. I made this for you, hope it will help you.
You don't need to save the player password in enum, just load it from database

PHP код:
case LoginPassword:
{
    if(
response)
    {
        new 
query[500], string[256], hashpass[129];
        
WP_Hash(hashpasssizeof(hashpass), inputtext);
        
mysql_format(MySQLquerysizeof(query), "SELECT * FROM `users` WHERE `Name` = '%e' AND `Password`='%e' LIMIT 1"GetName(playerid), inputtext);
        
mysql_tquery(MySQLquery"OnAccountLoad""i"playerid);
    }
    else
    {
        
SCM(playeridCOLOR_LIGHTRED"* Ai primit kick din cauza ca nu ai raspuns la dialog.")
        
SetTimerEx("DelayKick",200,false,"i",playerid);
    }
}
        
case 
RegisterPassword:
{
    if(
response)
    {
        if(
strlen(inputtext) < 5) return SendClientMessage(playerid, -1"* Your password must have at least 5 characters.");
        
ShowPlayerDialog(playeridRegisterPasswordDIALOG_STYLE_PASSWORD"Register""Please fill in your desired password:""Register""Quit");
        new 
query[500], IP[16];
        
GetPlayerIp(playeridIPsizeof(IP));
        
PlayerInfo[playerid][pSkin] = 37;
        
WP_Hash(PlayerInfo[playerid][pPassword], 129inputtext);
        
mysql_format(MySQLquerysizeof(query), "INSERT INTO `users` (`Name`, `Password`, `IP`, `Gender`, `Email`, `Skin`) VALUES ('%s', '%e', '%s', 0, 0, '%d')"GetName(playerid), PlayerInfo[playerid][pPassword], IP00PlayerInfo[playerid][pSkin]);
        
mysql_tquery(MySQLquery"OnAccountRegister""i"playerid);
    }
    else
    {
        
SCM(playeridCOLOR_LIGHTRED"* Ai primit kick din cauza ca nu ai raspuns la dialog.")
        
SetTimerEx("DelayKick",200,false,"i",playerid);
    }
}
forward DelayKick(playerid);
public 
DelayKick(playerid)
{
    
Kick(playerid);
    return 
1;
}
forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    if(
cache_num_rows())
    {
        
// User has entered correct password, load data
    
}
    else
    {
        
PasswordIncercari[playerid]--;
           if(
PasswordIncercari[playerid] == 0)
        {
            
SCM(playeridCOLOR_RED,"* Ai primit kick deoarece nu ai scris parola corecta de multiple ori.");
             
SetTimerEx("DelayKick",200,false,"i",playerid);
              
printf("[KICK-PASSWORD] %s has been kicked for entering the wrong password 2 times."GetName(playerid));
        }
        
format(stringsizeof(string), "* Ai scris o parola gresita, mai ai %d incercari."PasswordIncercari);
         
SendClientMessage(playeridCOLOR_REDstring);
         
ShowPlayerDialog(playeridLoginPasswordDIALOG_STYLE_PASSWORD"Login""Bine ai revenit!\nTe rugam sa te loghezi:""Login.""Quit.");
    }
    return 
1;

Reply
#5

Thank you so much guys, you helped me alot.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)