I'm currently working on a Java Application to connect to an Azure DB using JDBC. This is what my current code looks like -
File file = new File("filename.txt");
Scanner scanner = new Scanner(file);
String pwd = scanner.nextLine();
String connectionUrl =
"jdbc:sqlserver:{A link here};" +
"database={DBName}; +
"user={UserName};" +
"password=" + pwd + ";"
"encrypt=true;" +
"trustServerCertificate=false;" +
"hostNameInCertificate=*.database.windows.net;" +
"loginTimeout=30;";
I intend to upload this project publicly on Github when complete, and it obviously seems like a terrible idea to have a plain-text password there.
However, I'm not sure what the best way to do this is. I don't think storing a Hashed password would work, since the DB string requires it in plain-text. The best I could come up with was storing the password in a text document (along with several other words/text), and using the IO reader/substrings/BufferedReader to read it as a variable. This at least somewhat disguises it to the casual reader, but anyone that knows basic Java will still be able to identify it (or just put a simple System.out.print(pwd))
It does seem like there should be a better way, but I haven't found any workable solutions that prevent the user from just opening the text document/conf file and reading the password. I would like to keep the connection completely automated, so wouldn't want to prompt the user to enter the password. Responses on how to achieve this would be appreciated!
I am a (largely self-taught) student with limited practical experience when it comes to Java, so apologies if I've missed a fairly obvious solution.