Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

MYSQL Functions

Open yozel opened this issue 13 years ago • 4 comments

Hi (sorry for my english)

I have used salt for my user passwords. So, I should use mysql MD5 function like this:

...WHERE MD5(concat('$_POST['password']',salt))=password

How can i do this ? I think I can use the query() function but probably this cause sql injection.

Can you help me ?

yozel avatar Jul 15 '13 10:07 yozel

Why do not just use PHP native function to do this stuff? Like md5($_POST['password']', $salt)?

If you really want to build the query for yourself, you can use quote() to escapes special characters.

WHERE password=' . $database->quote("MD5(concat('$_POST['password']', salt)") . '

http://medoo.in/api/quote

catfan avatar Jul 16 '13 18:07 catfan

Using

...WHERE MD5(concat('$_POST['password']',salt))=password

is very bad for performance, because every (I repeat: EVERY) column-entry has to be be handled with md5. So if you have 1 mio. entries in the table you have to call mysql-function 'md5' 1 mio. times. Better idea, also for security reasons: store encrypted password in database and do a

WHERE password=$_POST['password']

Before that you can add salt.

fgusinde avatar Sep 04 '13 06:09 fgusinde

what about using sysdate(), or now(), or parse functions, like month(date_column), etc i think this is very important

drtobal avatar Jul 21 '14 07:07 drtobal

Yep, I'm currently using medoo in a small twitter app related project and I'm liking it, but I'm also wondering about using MySQL methods like NOW() because they are pretty essential.

rohan-deshpande avatar Jan 29 '15 09:01 rohan-deshpande