As Dani has mentioned security is a big issue here, using root to access a server is very insecure, the password should be changed on a regular basis.
Applications should have their own access and there should also be a separate file containing security access and passwords, otherwise anytime the password is changed then so will any application that uses it, you should consider changing your code to process your data in a more secure way.
I am sorry I haven't answered your specific problem but as an old school systems programmar, using Assembler, Pascal, Cobol and C with extended compilation times we made sure we didn't have to spend time on rewriting code to handle foreseeable problems.
In particular the application was given access to read the password file not the user and it made simple password changes much easier to routinely deal with, that didn't stop a few "smart" ones hard coding the application and wondering why it didn't work, even worse if someone else had to deal with the maintenance. Many heated arguments resulted. :)