Several times recently, I've needed to do stuff with connection strings, parsing individual tokens, and redacting sensitive info for display. I got tired of copying and pasting this code everywhere, so I decided to offer as a package. Examples:
var redacted = ConnectionString.Redacted("Server=whatever;Database=thisdb;User Id=adamo;Password=*gkdZ7W1#QsN@EAH");
Assert.IsTrue(redacted.Equals("Server=whatever;Database=thisdb;User Id=<redacted>;Password=<redacted>"));
var server = ConnectionString.Server("Server=(localdb)\\mssqllocaldb;Database=AnotherDb;Integrated Security=true");
Assert.IsTrue(server.Equals("(localdb)\\mssqllocaldb"));
var database = ConnectionString.Database("Server=(localdb)\\mssqllocaldb;Database=AnotherDb;Integrated Security=true");
Assert.IsTrue(database.Equals("AnotherDb"));
AO.ConnectionStrings.ConnectionString ConnectionString.cs
- string Token (string input, string token, [ string defaultValue ])
- string Token (string input, IEnumerable tokens, [ string defaultValue ])
- string Server (string input)
- string Database (string input)
- bool IsWellFormed (string input)
- Dictionary<string, string> ToDictionary (string input)
- string Redact (string input, [ string replaceWith ])
- bool IsSensitive (string input, Dictionary<string, string> redacted, [ string replaceWith ])