I'm designing a webapp from ground up.

From a security standpoint, assuming in both cases I will be hashing with a salt, a peper and a proper hashing algorithm.

Am I better off storing the user credentials in a database table along with the rest of the data, or in its own local file?

More specifically, would a separated design where the database user table contains the userID, name, email, etc. And the userID, password, salt are stored in a local file on the system. Is it worth the pain to design separately from a security standpoint, regarding the possible vectors of attack in general and if they're successful, to make the system more resilient.

  • The question is not very clear. Are you trying to have an "auto login", where the user will be signed in each time they use the app or? Commented Jan 31, 2017 at 1:27
  • @dark_st3alth thanks for your response. I added a paragraph to clarify
    – Wadih M.
    Commented Jan 31, 2017 at 1:29

2 Answers 2


Seems you are doing all the right things regarding crypto (salt, pepper, proper hashing algo). The additional security you might get by either going local file system or storing within a DB running on a different machine might not be significant.

If you go local file system

  • If possible turn on filesystem level encryption.
  • Set appropriate access permission on the file.

If you go the DB route

  • Make sure that machine running DB server is properly hardened.
  • If possible turn on DB encryption.
  • Ensure user authentication required to access DB.
  • If possible ensure Application Server to DB communication is over a secure channel

You should use a database, for the following reasons.

  1. Your web server is in the DMZ. The DMZ is less secure than the protected zone (where you would put your database), so any files you put there are going to be more vulnerable than the datafiles that hold your database.

  2. For passwords to offer maximum security, it must be possible for a user to change them. If you store them in the database, they are easier to change. Using a flat file for storage and updating it frequently can cause locking issues in a high volume environment; databases are designed to cope with high volume more effectively.

  3. If you are using a local flat file, your solution will not scale out to more than one web server. You could use a SAN I suppose, but I am not sure it is a great idea to give your web server service account filesystem access to the network; that is just one more resource a hacker may wish to exploit.

  4. A database solution is more amenable to non-repudiation since there are tran logs, backups, and you can create history tables. If you use a flat file, a malicious process could monkey with it and leave no trace.

  5. Many database platforms offer encryption. While this is not a panacea (you still need to use hashes, salts, and other mitigations) it does constitute defense in depth. Encrypting a file would require a bit more work and a little more risk that you get the implementation wrong.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .