SA-MP Forums Archive
I am getting logged-in typing any character I'd like - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: I am getting logged-in typing any character I'd like (/showthread.php?tid=461168)



I am getting logged-in typing any character I'd like - NeskWriter - 31.08.2013

Hey guys, I am trying to write a simple code that allows players register/login their/into their accounts. I have finished with register dialog, everything works fine, which can not be told about login. The problem is that while I type any character I am getting logged-in. I guess that I've made a mistake in comparing password with the inputtext. Here is the code:

PHP код:
#define DIALOG_REGISTER 0
#define DIALOG_LOGIN 1
#define DIALOG_QUIT 2
#define DIALOG_PASSLEN 3
#define DIALOG_WRONGPASS 4 
PHP код:
public OnPlayerConnect(playerid)
{
    new 
PlrFile[128];
    
format(PlrFilesizeof(PlrFile), "/Users/%s.txt"RetPlrName(playerid));
    if(!
fexist(PlrFile))
    {
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Registration""Please type your future password below:""Register""Cancel");
    }
    else
    {
        
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT"Logging-in""Please type your password below:""Login""Cancel");
    }
    return 
1;

PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_REGISTER)
    {
        if(
response == 0)
        {
            
ShowPlayerDialog(playeridDIALOG_QUITDIALOG_STYLE_MSGBOX"Cancelled""Use /q to exit""OK""");
            
Kick(playerid);
        }
        else if(
response == 1)
        {
            new 
KeyLen strlen(inputtext);
            if(
KeyLen <= || KeyLen >= 33)
            {
                
ShowPlayerDialog(playeridDIALOG_PASSLENDIALOG_STYLE_MSGBOX"Notice""The password must be between 6 and 32 symbols""OK""");
            }
            else
            {
                new 
PlrFile[128], File:PlrFileOpen;
                
format(PlrFilesizeof(PlrFile), "/Users/%s.txt"RetPlrName(playerid));
                
PlrFileOpen fopen(PlrFileio_write);
                
fwrite(PlrFileOpeninputtext);
                
fclose(PlrFileOpen);
            }
        }
    }
    else if(
dialogid == DIALOG_LOGIN)
    {
        if(
response == 0)
        {
            
ShowPlayerDialog(playeridDIALOG_QUITDIALOG_STYLE_MSGBOX"Cancelled""Use /q to exit""OK""");
            
Kick(playerid);
        }
        else if(
response == 1)
        {
            new 
PlrFile[128], File:PlrFileOpenpass[128];
            
format(PlrFilesizeof(PlrFile), "/Users/%s.txt"RetPlrName(playerid));
            
PlrFileOpen fopen(PlrFileio_read);
            
fread(PlrFileOpenpass);
            if(
strcmp(inputtextpassfalse32))
            {
                
SendClientMessage(playerid0xFFFFFFAA"You have successfully logged-in");
            }
            else
            {
                
ShowPlayerDialog(playeridDIALOG_WRONGPASSDIALOG_STYLE_MSGBOX"Error""You have typed wrong password""OK""");
            }
            
fclose(PlrFileOpen);
        }
    }
    else if(
dialogid == DIALOG_PASSLEN)
    {
        if(
response == 1)
        {
            
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Registration""Please type your future password below:""Register""Cancel");
        }
    }
    else if(
dialogid == DIALOG_WRONGPASS)
    {
        if(
response == 1)
        {
            
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT"Logging-in""Please type your password below:""Login""Cancel");
        }
    }
    return 
1;

The following callbacks are used only. Somebody, pimp my code.

And, yeah, create a folder called "Users" in the scriptfiles folder.


Re : I am getting logged-in typing any character I'd like - 1Geek - 31.08.2013

Guy use [PAWN] not [PHP]
try this
IF you want i have create one >
There is my system try to compare it with ur code
And Can someone help meHERE


Re: Re : I am getting logged-in typing any character I'd like - NeskWriter - 31.08.2013

Quote:
Originally Posted by 1Geek
Посмотреть сообщение
Guy use [PAWN] not [PHP]
try this
IF you want i have create one >
There is my system try to compare it with ur code
And Can someone help meHERE
Wow cool, thanks, and, yeah, link for YSI\y_ini include?


Re: I am getting logged-in typing any character I'd like - EiresJason - 31.08.2013

Does this work?

Strcmp actually returns 0 if the two strings are the same.

!Strcmp will counter it.
pawn Код:
else if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
            ShowPlayerDialog(playerid, DIALOG_QUIT, DIALOG_STYLE_MSGBOX, "Cancelled", "Use /q to exit", "OK", "");
            Kick(playerid);
        }
        else if(response)
        {
            new PlrFile[128], File:PlrFileOpen, pass[128];
            format(PlrFile, sizeof(PlrFile), "/Users/%s.txt", RetPlrName(playerid));
            PlrFileOpen = fopen(PlrFile, io_read);
            fread(PlrFileOpen, pass);
            if(!strcmp(inputtext, pass, false, 32))
            {
                SendClientMessage(playerid, 0xFFFFFFAA, "You have successfully logged-in");
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_WRONGPASS, DIALOG_STYLE_MSGBOX, "Error", "You have typed wrong password", "OK", "");
            }
            fclose(PlrFileOpen);
        }
    }



Re: I am getting logged-in typing any character I'd like - NeskWriter - 31.08.2013

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Does this work?

Strcmp actually returns 0 if the two strings are the same.

!Strcmp will counter it.
pawn Код:
else if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
            ShowPlayerDialog(playerid, DIALOG_QUIT, DIALOG_STYLE_MSGBOX, "Cancelled", "Use /q to exit", "OK", "");
            Kick(playerid);
        }
        else if(response)
        {
            new PlrFile[128], File:PlrFileOpen, pass[128];
            format(PlrFile, sizeof(PlrFile), "/Users/%s.txt", RetPlrName(playerid));
            PlrFileOpen = fopen(PlrFile, io_read);
            fread(PlrFileOpen, pass);
            if(!strcmp(inputtext, pass, false, 32))
            {
                SendClientMessage(playerid, 0xFFFFFFAA, "You have successfully logged-in");
            }
            else
            {
                ShowPlayerDialog(playerid, DIALOG_WRONGPASS, DIALOG_STYLE_MSGBOX, "Error", "You have typed wrong password", "OK", "");
            }
            fclose(PlrFileOpen);
        }
    }
Yeeeeeah it does, I'm kinda thanking you bro


Re: I am getting logged-in typing any character I'd like - EiresJason - 31.08.2013

Haha


Re : Re: Re : I am getting logged-in typing any character I'd like - 1Geek - 01.09.2013

Quote:
Originally Posted by NeskWriter
Посмотреть сообщение
Wow cool, thanks, and, yeah, link for YSI\y_ini include?
There is your link
https://sampforum.blast.hk/showthread.php?tid=321092