I have a web application in which users can log in. Due to technical constraints, the application is not allowed to store any session information on the disk.
To identify requests from the same user without storing sessions to disk, I have devised the following scheme:
The application has a long, randomly generated server side secret S, created at the time of installation. There is an user with an username u and a password p.
In order to log in, the user presents (u, p) to the web application for authentication at time t. If the authentication is successful, it sends out a cookie c in the response, containing Encrypt(u || t, S). Encrypt in this case is AES-256 in CBC mode of operation.
Later, when a request containing c arrives, the application decrypts the contents of c with S to obtain u and t. Obviously, if u is not a valid user, the request is rejected. Also, the request is rejected if the difference between the current time and t is greater than x. Rejecting the request involves asking the client to delete c and redirecting the user to the login page.
If the user sends a request at time t + y, such at k <= y <= x, the application refreshes c by updating it to Encrypt(u || t + y, S). k is chosen to be some suitable value, such as x/3.
Logging out simply involves asking the browser to delete c.
Is this method of authentication secure?