MD5 and MySQL
#1

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)