Where to store the user's connection information?
;) I am writing a .NET application that a user connects to a given server. ALl information in the application is stored on the server. But I want / have to store the following information for the user:
- The last server it connected to
- The username he used to connect the latter (and no, no password, never).
Any idea where to store this best? the application config file is not sane (user! = admin, application.config is write protected). So my options are:
- In the registry. 2 under my own division.
- As an ini file stored in the user data directory (AppData). This may also allow for later extensions (for example, storing additional information, some of which may not fit into the registry).
Can anyone tell me? Other alternatives? I still prefer AppData directories with my own subfolder - simply because it's good preparation to save as a local copy of the configuration later, etc.
a source to share
You can save in app.config as a custom parameter (so they are not stored in the app.config file after they are changed, but can be accessed using the same APIs).
See here for more information on the scope:
http://msdn.microsoft.com/en-us/library/a65txexh%28VS.80%29.aspx
a source to share
How to do what dineshrekula wrote below:
using System.Security;
using System.Security.Cryptography;
var guid = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(System.Runtime.InteropServices.GuidAttribute), false);
this.entropy = Encoding.UTF8.GetBytes((guid[0] as System.Runtime.InteropServices.GuidAttribute).Value);
private SecureString Unprotect(byte[] data)
{
return UTF8Encoding.UTF8.GetString(ProtectedData.Unprotect(data, this.entropy, DataProtectionScope.CurrentUser)).ToSecureString();
}
private void Protect(string data)
{
ProtectedData.Protect(UTF8Encoding.UTF8.GetBytes(data), this.entropy, DataProtectionScope.CurrentUser)
}
a source to share