by JBrooks
19. November 2010 07:44
I have a page in my ASP.Net application where I show all of my AppSettings, connection strings, etc. But I didn’t want to show the passwords. I wanted something like:
server=MyServer;uid=MyUserId;pwd=*******;database=MyDatabase;
So here is the code to strip out the password:
private string stripPassword(string connString)
{
if (string.IsNullOrEmpty(connString))
return connString;
int pos = connString.ToLower().IndexOf("pwd");
if (pos > -1)
pos += 4;
else
{
pos = connString.ToLower().IndexOf("password");
if (pos > -1)
pos += 9;
else
return connString;
}
return connString.Substring(0, pos) + "*******" +
connString.Substring(pos + connString.Substring(pos).IndexOf(";"));
}
f13b0ecf-1b05-4a9e-955f-7eda7bdf566c|1|4.0|27604f05-86ad-47ef-9e05-950bb762570c
Tags:
ASP.Net | Development