I've been working on a Java project for a while now, and before I make it available for public download, I'd like to add in a feature which requires me to connect to a MySQL database. My question is simple: How would I go about hiding the password to the database if the code is open-source?
Store the database connection settings separate from your code.
You can put the password in some sort of configuration file
like an ini
file. During the setup/installation stage, get the password from the user and populate it in the configuration file either by code, or allow them to do it manually.
As far as I know, there is no correct answer. You can try really hard to obfuscate or hide it, but if the password or a method of calculating it is in your JAR, a persistent and skilled user will find it.
There is a much better answer than I could give here: How can I protect MySQL username and password from decompiling?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With