That logic should be in the application, then you'll simply compare the calculated value against what's stored in the database.
(If not in the application, you could use functions in MySQL, but I wouldn't recommend that approach. I like to keep all application logic in one place if possible, not spread in different parts.)
If you run functions like that in the WHERE
clauses of your query, MySQL will be unable to use an index on passwd
because it has to calculate something for every value in the passwd
column. Instead, do your salting and hashing in your application, then compare that final string against your stored info in a plain query that can use an index, like this
SELECT * FROM mytable WHERE email=@email AND passwd=@pwdhash