Small Problem
#1

hi all....

i got a little bit problem here...

i made a register dialog with a password ccomfirmation. when he enter the password, the confirmation dialog showed, but when he re enter the password (on the confirmation dialog), the "register ok" is not printed :/

the register dialog response

pawn Код:
format(RegPass[playerid], 64, inputtext);
                    ShowPlayerDialogLang(playerid, EN, DIALOG_REGISTER_REENTER, DIALOG_STYLE_PASSWORD, "Register: Confirmation", "{FFFFFF}Please re-enter your password\n\n{DDDDDD}Just for password confirmation", "Register", "Back");
                    ShowPlayerDialogLang(playerid, ID, DIALOG_REGISTER_REENTER, DIALOG_STYLE_PASSWORD, "Register: Confirmation", "{FFFFFF}Mohon untuk memasukkan kembali password anda\n\n{DDDDDD}Hanya untuk konfirmasi password", "Daftar", "Kembali");
the confirmation dialog response

pawn Код:
for(new i; i < 64; i++)
                    {
                        if(inputtext[i] != RegPass[playerid][i])
                        {
                            ShowPlayerDialogLang(playerid, EN, DIALOG_REGISTER_REENTER, DIALOG_STYLE_PASSWORD, "Register: Confirmation", "{FF0000}Password doesn't match!\n\n{FFFFFF}Please re-enter your password\n\n{DDDDDD}Just for password confirmation", "Register", "Back");
                            ShowPlayerDialogLang(playerid, ID, DIALOG_REGISTER_REENTER, DIALOG_STYLE_PASSWORD, "Register: Confirmation", "{FF0000}Password tidak cocok!\n\n{FFFFFF}Mohon untuk memasukkan kembali password anda\n\n{DDDDDD}Hanya untuk konfirmasi password", "Daftar", "Kembali");
                            return 1;
                        }
                    }
                    new escpass[100];
                    mysql_escape_string(inputtext, escpass);
                    MySQL_Register(playerid, escpass);
                    printf("register ok");
Reply
#2

Obviusly because that "return 1;" there skips it. Why you loop through the whole string is beyond me when you know you can use a native function strcmp. Also, that's not how you use "format", for copying strings use a hand-written function called strcpy.
Reply
#3

i use "return 1;" to break the loop (instead of break :3). and i think it's will only called if the confirmation password isn't equal with the password.

but, ah... i will try what did you said :3
Reply
#4

Quote:
Originally Posted by AiRaLoKa
Посмотреть сообщение
i use "return 1;" to break the loop (instead of break :3). and i think it's will only called if the confirmation password isn't equal with the password.

but, ah... i will try what did you said :3
At the first place you don't even need to loop?!
https://sampwiki.blast.hk/wiki/Strcmp as Virtual1ty already suggested.
Reply
#5

You can't possibly expect every player's password to be 64 characters long. Let's say they type 'abc123' into the box (a very bad, yet common password) then the length is 6, not 64. This means you're going out of bounds all the time.

To compare strings, you use the function that was designed for this purpose: strcmp.
Reply
#6

so did what i done now is the correct one?

i cant test it becouse i cant open my game panel :3

pawn Код:
strcpy(RegPass[playerid], inputtext);
pawn Код:
if(!strcmp(inputtext, RegPass[playerid], false, 64))
                    {
                        new escpass[100];
                        mysql_escape_string(inputtext, escpass);
                        MySQL_Register(playerid, escpass);
                        printf("register ok");
                        return 1;
                    }
edit:

https://sampwiki.blast.hk/wiki/Using_strcmp%28%29

i see there is two different usage

pawn Код:
if(!strcmp(cmdtext, "/me", true, 3))
and

pawn Код:
if(strcmp(cmd, "/sayhello", true) == 0)
so what is the different?
Reply
#7

It's exactly same just handles different way of returns.
Код:
-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).
Reply
#8

so it's mean that i have to use the second way?

from

pawn Код:
if(!strcmp(inputtext, RegPass[playerid], false, 64))
into

pawn Код:
if(strcmp(inputtext, RegPass[playerid], false) == 0)
right?

or it just the same?

the different only the size right?

edit:

i used the seccond way and it's works like a charm \ /

+REP for all
Reply
#9

if (!...) is the same as if (...) == 0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)