I'm trying to avoid DB access upon authentication to improve performance
a valid solution after lots of searching seems to be storing an encrypted string in cookie and try to decrypt it upon authentication.
Thus, I am wondering if the following is a good idea:
- transmit everything via SSL (I'm lazy..)
- set a global constant secret key in my program
- generate a new random verification string upon registration and password change, store it in the User object
- generate an encrypted verification string with verification string and secret key
- store the unencrypted and encrypted verification strings in the cookie
- when user tries to login, decrypt the verification string and check against the original verification string
if it is an "OK" idea, how do I actually make it work, like:
what encryption method should I use, AES-256?
how do I do this kind of encryption/decryption in Java, using Bouncycastle?
if it is not a good idea, what should I do to avoid querying DB on authentication?
thans in advance!