Help STRCMP
#1

I have this code
Код:
if(dialogid == DIALOG_LOGIN && response == 1)
	{
	    new file[256], pname[MAX_PLAYER_NAME];
	    new pass[256];
		GetPlayerName(playerid, pname, sizeof(pname));
	    format(file, sizeof(file), "Accounts/%.txt", pname);
		pass = dini_Get(file, "Password");
		if(strcmp(inputtext,pass, false) !=0 ) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Information", "Please Enter Your Password, You Have Entered Wrong Password", "Enter", "Quit");
When I type WRONG password its dont show me error dialog , its continue normal
Reply
#2

Anyone ?
Reply
#3

You first need to check if the inputtext is a null string before comparing both strings. You could use this useful macro by ******:

PHP код:
#if !defined isnull
    #define isnull(%1)                     ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
PHP код:
if(isnull(inputtext))
    {
        
//Do something: display a dialog saying no text was input
        
return 0;
    } 
Reply
#4

pawn Код:
if(strcmp(inputtext,pass, false) == 0) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Information", "Please Enter Your Password, You Have Entered Wrong Password", "Enter", "Quit");
strcmp(); returns 0, if the string matches, and 1 if it doesn't. strcmp on the wiki


ThePhenix is right also. You'd need to check if the inputtext is there, and not null.

It also looks like you're not hashing passwords. I strongly suggest you do.
Reply
#5

Quote:
Originally Posted by ThePhenix
Посмотреть сообщение
You first need to check if the inputtext is a null string before comparing both strings. You could use this useful macro by ******:

PHP код:
#if !defined isnull
    #define isnull(%1)                     ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif 
PHP код:
if(isnull(inputtext))
    {
        
//Do something: display a dialog saying no text was input
        
return 0;
    } 
it does not work
Reply
#6

DobbysGamertag pointed out something very important. It's really irresponsible from your part not to use any hashing method to store passwords. I recommend you to use bcrypt.
Reply
#7

I've Added Those Colored in RED
Код:
	if(dialogid == DIALOG_LOGIN && response == 1)
	{
	    new file[256], pname[MAX_PLAYER_NAME];
	  	//new pass[256];
		GetPlayerName(playerid, pname, sizeof(pname));
	    format(file, sizeof(file), "Accounts/%.txt", pname);
		//pass = dini_Get(file, "Password");
		if(isnull(inputtext))
    	{
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login Information", "Please Enter Your Password, No Password Has Entered", "Enter", "Quit");
   	    	return 0;
    	}
		if(strcmp(inputtext, dini_Get(file, "Password"), false) !=0) return 1;
		new str3[180];
		format(str3, sizeof(str3), "Your Password Is %s", dini_Get(file, "Password"));
		printf(str3);
		format(str3, sizeof(str3), "INPUTTEXT Is %s", inputtext);
		printf(str3);
And I got those lines on command line
https://imgur.com/iYRNHbn
my password stored in file is 32363236
inputtext is 322
and its login without showing any errors
please help
Reply
#8

i've spent time on it fuck
its solved..
i forget to put "s" after "%"

here was the fucking line:
Код:
format(file, sizeof(file), "Accounts/%s.txt", pname);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)