Before I re-invent the wheel, is there a standard way to hide at least a password in a SQL Server connection string?
(Written in C#)
I have a highly multi-threaded app that is aware of multiple databases, and so to aid in troubleshooting and debugging there are various places where the connection string can be logged. I can't control what customers using this product use for connection strings and so it's not at all uncommon to find passwords in them. I know this because it's also not uncommon that people turn on DEBUG-level logging and send us log files along with a problem report, and those logs contain their database passwords (and as a result our support ticket system contains passwords).
I realize best practice is to NOT put passwords in connection strings, but that part is out of my control (unless of course we change our app so it refuses to run if you give it a connection string with an unencrypted password... that seems a bit draconian to me).
Really want I want it to log is:
Server=myServerAddress;Database=myDataBase;User Id=****;Password=*****;
(I'm up in the air over if User id/name is a sensitive thing or not, and/or useful to log or not -- comments on that welcome).
I could build a simple regex (eg /Password=[^;]+/
), but before I do I just want to see if there are other cases I'm not considering, especially if this is done already.