I am going through this tutorial and I am using the ENCRYPT MySQL function.
But now I have the problem of how to decrypt the encrypted password in MySQL or in php? I want to compare if the password entered is the same as the encrypted one.
How can I compare it? MySQL must be encrypted with the ENCRYPT function!
I am searching but I can not find anything how to decrypt the ENCRYPT MySQL function...
解决方案
ENCRYPT is using a one way hash algorithm there is no DECRYPT.. That's the sense of enrypting passwords: a hacker should have no option to see the clear text passwords.
When you need to compare a password in db with one a user has entered, use a query like this (using prepared queries)
SELECT * FROM `user`
WHERE `name` = 'hek2mgl`
AND `password` = ENCRYPT('user_input', `password`)
The ENCRYPT function will output a "salted" string prefixed with the salt itself, so feeding it back the encrypted password will re-supply the original salt.