This is a really interesting question. I am joining.
You must encrypt it when storing it. No matter how you look at it, this is better than storing it in plain text. Let it be said that the attacker discovers that the SQL injection declares db, it still does not hold the encryption key. On the other hand, if he gets access to the server, he will probably also find the encryption key.
To improve it a bit, you can save the encryption key in the server configuration. Assuming you are using Apache, you can use SetEnv .
I need to enter the encryption key in my environment when Apache starts, then it is saved as the en environment variable, so the key is not actually stored anywhere on my server.
There is no way if you do not require the user to enter a key to decrypt the password, on which you will be 100% more secure.
source share