This logic should be in the application, then you just compare the calculated value with what is stored in the database.
(If not in the application, you can use functions in MySQL, but I would not recommend this approach. I like to maintain all the application logic in one place, if possible, and not be distributed in different parts.)
If you perform such functions in the WHERE clauses of your query, MySQL will not be able to use the index in passwd because it needs to calculate something for each value in the passwd column. Instead, do your salting and hashing in your application, and then compare this final line with your stored information in a regular query that can use an index like this
SELECT * FROM mytable WHERE email=@email AND passwd=@pwdhash
source share