Search code examples
ruby-on-railsdevisecross-domainsecuritybasic-authentication

Encrypting (not hashing) and storing user passwords on a rails server, using devise cookies


Got a bit of an issue where I am required to maintain a secure connection with one server that proxies out requests to another, over basic authentication. However I can't be allowed to gain access to the password for the users who want to access the other server. Can anyone suggest a way to store the password (having been given it once) securely in say the session variable, encrypted by a key that only the client holds until the point when it's needed?

After a time it can expire, ie, you could give the username and password and half an hour would be an acceptable time to keep the credentials in case the user wanted to access the site again.


I've rewritten this a few times after producing pure waffle, sincerely sorry if the editing didn't make much difference.


Solution

  • If your server is going to be handling the password in plaintext (to talk to the other server with Basic auth), you're going to gain access to the password. Perhaps you want to avoid storing the password in plaintext?

    Send the password in plain text to the server, which then encrypts it, stores the encrypted version and adds a cookie to the client with the key. Then any future requests provide the key to the server.

    If you're looking for an encryption library, Recommended two-way encryption gems for Ruby?