Register/ Login Help
#1

Hello,

Here is my problem: When a user registers the password saves and everything but, when they go to login they can type any password they want and it accepts the login. If they don't type anything it says incorrect password. But, when they type 12345454a1f23sd1f for example it will allow them to log-in.

Here is the code:
pawn Код:
else if(dialogid == 1) // Register
    {
        if(response)
        {
            if(strlen(inputtext) < 4)
            {
             SendClientMessage(playerid, COLOR_GREY, "Password can't be shorter than 4 characters.");
             ShowDialog(playerid, 1);
             return 1;
            }
            if(strlen(inputtext) > 256)
            {
                SendClientMessage(playerid, COLOR_GREY, "Password can't be longer than 256 characters.");
                ShowDialog(playerid, 1);
                return 1;
            }
            new file[64], IP[16], string[128], password[256];
            format(file, sizeof(file), "users/%s.ini", RPNU(playerid));
            if(!dini_Exists(file))
            {
                GetPlayerIp(playerid, IP, sizeof(IP));
                dini_Create(file);
                WP_Hash(password, sizeof(password), inputtext);
                dini_Set(file, "Password", password);
                dini_Set(file, "IP", IP);
                PlayerInfo[playerid][pLevel] = 1;
                dini_IntSet(file, "Level", PlayerInfo[playerid][pLevel]);
                format(string, sizeof(string), "SERVER: {FFFFFF}You have successfully registered on {FF6347}Union Gaming Roleplay{FFFFFF}. (Password: %s)", inputtext);
                TotalRegister++;
                SendClientMessage(playerid, COLOR_LIGHTRED, string);
                ShowDialog(playerid, 2);
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You have chosen to quit the server.");
            Kick(playerid);
        }
    }
    else if(dialogid == 2) // Login
    {
        if(response)
        {
            new file[64], password[256], IP[16], password2[256];
            format(file, sizeof(file), "users/%s.ini", RPNU(playerid));
            WP_Hash(password2, sizeof(password2), inputtext);
            format(password, sizeof(password), "%s", dini_Get(file, "Password"));
            if(strcmp(password, inputtext,true) && strcmp(password, password2, true))
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}Invalid password.");
                ShowDialog(playerid, 2);
                return 1;
            }
            if(dini_Int(file, "AdminAccount") == 1)
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You can't login directly from an admin account.");
                Kick(playerid);
                return 1;
            }
            else if(sscanf(inputtext, "s[128]", inputtext))
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
                ShowDialog(playerid, 2);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                format(PlayerInfo[playerid][pIP], 16, "%s", dini_Get(file, "IP"));
                GetPlayerIp(playerid, IP, sizeof(IP));
                dini_Set(file, "IP", IP);
                PlayerInfo[playerid][pGender] = dini_Int(file, "Gender");
                PlayerInfo[playerid][pAge] = dini_Int(file, "Age");
                if(!PlayerInfo[playerid][pGender] || !PlayerInfo[playerid][pAge])
                {
                    ShowDialog(playerid, 3);
                }
                else
                {
                    LoadChar(playerid);
                    SpawnPlayer(playerid);
                }
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You have chosen to quit the server.");
            Kick(playerid);
        }
    }
Reply
#2

pawn Код:
else if(sscanf(inputtext, "s[128]", inputtext))
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
                ShowDialog(playerid, 2);
                return 1;
            }
sscanf on a dialog o.O

use this:

pawn Код:
//dont need the else if, just write if(blah blah)
if(strlen(inputtext) <= 0 || strlen(inputtext) > 68)// change the 68 to the max length of the password.
{
     SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
     ShowDialog(playerid, 2);
     return 1;
}
Reply
#3

Quote:
Originally Posted by kamzaf
Посмотреть сообщение
pawn Код:
else if(sscanf(inputtext, "s[128]", inputtext))
            {
                SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
                ShowDialog(playerid, 2);
                return 1;
            }
sscanf on a dialog o.O

use this:

pawn Код:
//dont need the else if, just write if(blah blah)
if(strlen(inputtext) <= 0 || strlen(inputtext) > 68)// change the 68 to the max length of the password.
{
     SendClientMessage(playerid, COLOR_LIGHTRED, "SERVER: {FFFFFF}You must enter a password to procceed.");
     ShowDialog(playerid, 2);
     return 1;
}
Thanks but, the thing is If a user types in any password (correct or not) it allows them to log-in.
Reply
#4

heres your error, dont put else {, check the password again with strcmp and then proceed with the login.
pawn Код:
else
            {
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                format(PlayerInfo[playerid][pIP], 16, "%s", dini_Get(file, "IP"));
                GetPlayerIp(playerid, IP, sizeof(IP));
                dini_Set(file, "IP", IP);
                PlayerInfo[playerid][pGender] = dini_Int(file, "Gender");
                PlayerInfo[playerid][pAge] = dini_Int(file, "Age");
                if(!PlayerInfo[playerid][pGender] || !PlayerInfo[playerid][pAge])
                {
                    ShowDialog(playerid, 3);
                }
                else
                {
                    LoadChar(playerid);
                    SpawnPlayer(playerid);
                }
            }
Reply
#5

Quote:
Originally Posted by kamzaf
Посмотреть сообщение
heres your error, dont put else {, check the password again with strcmp and then proceed with the login.
pawn Код:
else
            {
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                SendClientMessage(playerid, COLOR_LIME, "");
                format(PlayerInfo[playerid][pIP], 16, "%s", dini_Get(file, "IP"));
                GetPlayerIp(playerid, IP, sizeof(IP));
                dini_Set(file, "IP", IP);
                PlayerInfo[playerid][pGender] = dini_Int(file, "Gender");
                PlayerInfo[playerid][pAge] = dini_Int(file, "Age");
                if(!PlayerInfo[playerid][pGender] || !PlayerInfo[playerid][pAge])
                {
                    ShowDialog(playerid, 3);
                }
                else
                {
                    LoadChar(playerid);
                    SpawnPlayer(playerid);
                }
            }
Can you give me the SSCANF code for checking if the password is correct?
Reply
#6

anyone?
Reply
#7

Remove the if statement with the sscanf and use isnull. Also, use this for checking the password
pawn Код:
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
pawn Код:
if( strcmp( dini_Get( file, "Password" ), password2 ) )
{
    // wrong password;
}
else
{
    // welcome back!
}
Reply
#8

Quote:
Originally Posted by Dwane
Посмотреть сообщение
Remove the if statement with the sscanf and use isnull. Also, use this for checking the password
pawn Код:
#if !defined isnull
    #define isnull(%1) \
                ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
pawn Код:
if( strcmp( dini_Get( file, "Password" ), password2 ) )
{
    // wrong password;
}
else
{
    // welcome back!
}
Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)