I'm in the process of building an app to let users sign up, connect their many email accounts (like Gmail) to the site, and allow email-related activities... like sending an email (please don't ask or say "oh the user can just go to their mail clients or Gmail tab to do that!", i know i know.) You could say i'm making an online mail client. I tried to explore how ThunderBird, Outlook, or Apple's Mail client manage login credentials, but I couldn't quite figure it out.
The Approach:
When they submit their email's login and password for the first time to my app, we do the following:
- salt the username and password with a 30 to 40 char key (different for every user)
- use AES-256 encryption (username and password have different keys stored elsewhere)
- then store the encrypted username and encrypted password
I'm aware of the theories, industry-recognized approaches to use one-way hashes and the many open source libraries, but my app needs to submit the user's email credentials, say, every time they want to send an email.
Here is a sample output of a user's email settings record stored in the database (using Rails):
#<EmailSetting id: 10, user_id: 3,
username: "{\"v\":1,\"adata\":\"\",\"ks\":256,\"ct\":\"E1M3+Eza9w5yNIoBVS...",
password: "{\"v\":1,\"adata\":\"\",\"ks\":256,\"ct\":\"8N/Ylh7IGiHKDz1QM7...",
outgoing_server: "smtp.gmail.com",
incoming_server: nil,
email_connection_type: nil,
outgoing_port: 587,
outgoing_authentication_type: "plain">
I'd like to make sure that if this database is ever compromised, i can protect the user's as best as i can while providing a service.
Question: is this strong enough to protect email login credentials? Is there anything i might be forgetting in protecting the database table?