I am making a little project that requires me to access one of my email accounts frequently to send emails. With that being said, I obviously know the log-in information ahead of time, and in order to protect the password from being created into a SecureString multiple times, I have created a Singleton class:
public sealed class Sender
{
#region Private Member Variables
private readonly static Sender SingletonSender = new Sender(); // Singleton object
private readonly SecureString password;
private const String defaultEmailAddress = "xxxxxxxxxxxxx";
#endregion
#region Properties
public static Sender ReminderSender
{
get { return SingletonSender; }
}
#endregion
#region Constructors
private unsafe Sender()
{
Char[] passwordCharacters = {/* password characters */};
fixed (Char* pwChars = passwordCharacters)
{
password = new SecureString(pwChars, passwordCharacters.Length);
}
password.MakeReadOnly();
passwordCharacters = null;
}
#endregion
// Additional methods
}
Now, I am wondering if this is the correct way to protect the password from being exposed unnecessarily? Additionally, if anyone has a better strategy to solve this, I would love to hear it. Note, that my goal of this application is to have it deployed on various PC's not just on my own.