SA-MP Forums Archive
MD5 and MySQL - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MD5 and MySQL (/showthread.php?tid=205656)



MD5 and MySQL - [L3th4l] - 01.01.2011

1st of all, DON'T post stuff that does not relate this.

So I want to hash passwords with MySQL and MD5, i used to use other hash, stock version. But I want to use the MD5 that comes with MySQL

So this is the reg system
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `Accounts` (`Username`, `Password`) VALUES ('%s', md5('%s'))", EscName, EscPass, PIP);
mysql_query(Query);
Ok, that works good. But how would i log in?

This is the log in bit:
pawn Код:
format(Query, sizeof(Query), "SELECT * FROM `Accounts` WHERE `Username` = '%s' AND `Password` = '%s'", pName(playerid), EscPass);

mysql_query(Query);
mysql_store_result();

if(!mysql_num_rows())
{
    // Incorrect Pass
}
else
{
    // Correct Pass
}



Re: MD5 and MySQL - Vince - 01.01.2011

Код:
SELECT * FROM `Accounts` WHERE `Username` = '%s' AND `Password` = md5('%s')



Re: MD5 and MySQL - _rAped - 01.01.2011

Quote:
Originally Posted by Vince
Посмотреть сообщение
Код:
SELECT * FROM `Accounts` WHERE `Username` = '%s' AND `Password` = md5('%s')
What he said...

Btw, use this instead:
pawn Код:
if(mysql_num_rows() > 0)
{
    // Correct Pass
}
else
{
    // Wrong pass
}



Re: MD5 and MySQL - FreshDoubleX - 01.01.2011

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
pawn Код:
format(Query, sizeof(Query), "INSERT INTO `Accounts` (`Username`, `Password`) VALUES ('%s', md5('%s'))", EscName, EscPass);
mysql_query(Query);
You had there PIP, but it shouldn't be there.


Re: MD5 and MySQL - _rAped - 01.01.2011

Quote:
Originally Posted by FreshDoubleX
Посмотреть сообщение
You had there PIP, but it shouldn't be there.
Won't affect the result anyways, but you are right


Re: MD5 and MySQL - Sergei - 01.01.2011

Quote:
Originally Posted by _rAped
Посмотреть сообщение
pawn Код:
if(mysql_num_rows() > 0)
{
    // Correct Pass
}
else
{
    // Wrong pass
}
Why so? If without conditions is faster, isn't that logical? Don't know why do oyu use mysql_num_rows here actually since you need mysql_retrieve_row or mysql_fetch_row anyway and they already return 1 if there's result.