String Compare - Riddy - 28.07.2013
Ok, been confused. I've been trying to compare a Whirlpool hash from one that is in a database.
pawn Code:
new rows, fields, currentPass[164];
cache_get_data(rows, fields);
if(rows)
{
cache_get_field_content(0, "Password", currentPass);
}
new hashedPass[129];
WP_Hash(hashedPass, sizeof(hashedPass), playerPass);
if(!strcmp(hashedPass, currentPass, false, 129))
{
new dialog[300];
format(dialog, sizeof(dialog),
"Welcome back, %s\n \
Please enter your password below",
PlayerName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,
"Logging", dialog, "Login", "Cancel");
print("Incorrect");
}
else
{
new query[300];
format(query, sizeof(query), "SELECT * FROM accounts WHERE `Username` = '%s'",
PlayerName(playerid));
mysql_tquery(cHandle, query, "LoginPlayer", "i", playerid);
print("Continue");
return 1;
}
This doesn't seem to work, and it's definitely working (the hashing and getting the password). It just skips over to the
else { }
instead of the first. Which is confusing, I am putting the incorrect password.
Re: String Compare -
MP2 - 29.07.2013
You're doing this:
pawn Code:
if(password is right)
{
tell them it's wrong
}
else
{
tell them it's right
}
Swap the code around.
You're also checking their password if they don't have an account (if 'rows' is 0) - shouldn't you be asking them to register or something?
Re: String Compare - Riddy - 29.07.2013
Quote:
Originally Posted by MP2
You're doing this:
pawn Code:
if(password is right) { tell them it's wrong } else { tell them it's right }
Swap the code around.
You're also checking their password if they don't have an account (if 'rows' is 0) - shouldn't you be asking them to register or something?
|
Nah, I've gone through that phase. I'm just getting the player password currently and comparing it. And, I've tried it in all ways, it just refuses to compare them \ correctly.
EDIT: And I added the exclamation mark, which means, if the string is incorrect.
Re: String Compare -
jamesbond007 - 29.07.2013
!strcmp means the string matches... look on wiki
Re: String Compare -
MP2 - 29.07.2013
Quote:
Originally Posted by Riddy
EDIT: And I added the exclamation mark, which means, if the string is incorrect.
|
Wrong. Look up the return values of strcmp. You'd assume a match would return 1/true - but this is not the case.
https://sampwiki.blast.hk/wiki/Strcmp
If strcmp returns 0, there is a match.
Re: String Compare - Riddy - 29.07.2013
Quote:
Originally Posted by jamesbond007
!strcmp means the string matches... look on wiki
|
I doubled-checked the wiki plenty of times, I must have missed it.
I've been using it wrongly for the past year then, but they've worked, but I dunno.
EDIT: Yes MP2, I was wrong.
Re: String Compare -
jamesbond007 - 29.07.2013
Quote:
Originally Posted by MP2
Wrong. Look up the return values of strcmp. You'd assume a match would return 1/true - but this is not the case.
https://sampwiki.blast.hk/wiki/Strcmp
If strcmp returns 0, there is a match.
|
basically thats what i just said before u
Re: String Compare -
MP2 - 29.07.2013
Quote:
Originally Posted by jamesbond007
basically thats what i just said before u
|
Due to the 2 minute posting limit I tend to write ~5 or so replies then post them every two minutes (making it possible to reply after not seeing other replies for 10 minutes (5 x 2). I should really stop doing that as this keeps happening. Apologies. Stupid limit is stupid.