I'm in need of a safe way to store a password in a database, but I also need a way to get the original password back. Of course if this was not the case I would just hash it. To work around this problem I came up with the following solution, but I would like to know if its secure.
I have a secret key on the server, and another secret key that is saved in the client-side application. The latter is different for every user and a new key is generated every time a user logs in.
The only time the server will have both keys is when a user makes a request and the server needs to get the raw password. This means that when the server is breached the passwords are still secure, since you only have half of the total key, and since I'm using AES 256, you still need to crack 128bits.
Is this OK or am I missing something important?
Edit: I need to use the client's password in API calls to external services