SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/04/2018, 05:41 PM   #1
Similarty
Little Clucker
 
Similarty's Avatar
 
Join Date: Mar 2018
Posts: 8
Reputation: 0
Post Hi guys.

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.
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
Code:
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
Similarty is offline   Reply With Quote
Old 16/04/2018, 06:04 PM   #2
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 567
Reputation: 31
Default Re: Hi guys.

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 Code:
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

__________________
Offering php and pawn scripts against payment. PM me.

[Filterscripts] SQLlite - Jaspers Pin Code Script - Additional security.
[Filterscripts] Jasper's Woodcutting job/skill with levels and XP. Custom map
[Filterscripts] Simple trucking filterscript
jasperschellekens is online now   Reply With Quote
Old 16/04/2018, 06:07 PM   #3
Similarty
Little Clucker
 
Similarty's Avatar
 
Join Date: Mar 2018
Posts: 8
Reputation: 0
Default Re: Hi guys.

Thank you I will try this tommorow.
Similarty is offline   Reply With Quote
Old 16/04/2018, 06:09 PM   #4
kovac
Huge Clucker
 
kovac's Avatar
 
Join Date: Mar 2018
Posts: 280
Reputation: 3
Default Re: Hi guys.

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 Code:
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;

kovac is offline   Reply With Quote
Old 16/04/2018, 06:11 PM   #5
Similarty
Little Clucker
 
Similarty's Avatar
 
Join Date: Mar 2018
Posts: 8
Reputation: 0
Default Re: Hi guys.

Thank you so much guys, you helped me alot.
Similarty is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help guys kevi11 Scripting Help 3 10/06/2016 06:47 PM
Hey GuyS.... Haz Scripting Help 2 18/12/2013 11:56 AM
Hey guys xxRichixx Everything and Nothing 17 02/04/2013 02:46 AM


All times are GMT. The time now is 01:23 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.