Secure Solution: Do not store You correctly identified that storing the hash anywhere on the disk makes the password vulnerable to attacks such as breaching file access control, known cypher-text attacks, or chosen cypher-text attacks.
Security Solution: Do not store a hashed password on the disk.
Since your database is just a hashedfile we can use the general way to securely password protect a file on the disk.
StepsAlgorithm To Securely Password Protect A File:
- Have the user input a password at runtime for the databasefile. (database in your case)
- Hash the password. (useI'd use SHA-256)
- Use the hash to derive a symmetric 256-bit key. (orI'd use hash directly as the key)
- Use the 256-bit key to encrypt/decrypt the database file on the disk. (useI'd use the AES algorithm)
ProMajor Pro: Database encryption key is generated at run-time and never stored on the disk (only in memory).
ConMinor Con: Encryption and key derivation becomes implementation specific and time consuminglaborous to implement.
You get to decide whether the required security for the application is worth the time to implement the security protocols correctly.
PS: This is the general way to securely password protect a file on disk, and the database is just a file.