I am getting logged-in typing any character I'd like
#1

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.
Reply
#2

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
Reply
#3

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?
Reply
#4

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);
        }
    }
Reply
#5

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
Reply
#6

Haha
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)