If you use a StringBuilder
instead of a string
, you can overwrite the actual value in memory when you are done. That way the password won't hang around in memory until garbage collection picks it up.
StringBuilder.Append(plainTextPassword);
StringBuilder.Clear();
// overwrite with reasonably random characters
StringBuilder.Append(New Guid().ToString());