views:

44

answers:

3

;) I am writing a .NET application wher ethe user connects to a given server. ALl information within the application is stored in the server. But I want / need to store the following information for the user:

  • The server he connected to last
  • The username he used to connect last (and no, no password, never ever).

Any idea where to store this best? the application config file is not sensible (user != admin, application.config is write protected for him). So, my options are:

  • In the registry. 2 keys under my own subkey.
  • In a sort of ini file, stored in the user's data directory (AppData). This would possibly also allow later expansion (into like saving more information, some of which may not fit into the registry).

Anyone a tip? Other alternatives? I tend so far to go for the AppData directory with my own subfolder - simply because it is a nice preparation for later to keep like a local copy of configuration etc.

+1  A: 

You can store in the app.config as a user setting (so they're not really stored in the app.config after they've changed but can be accessed with the same APIs).

See here for more information regarding Scope:

http://msdn.microsoft.com/en-us/library/a65txexh%28VS.80%29.aspx

ho1
And how exactly would this allow the user to write into the application directory. Even a user.config living there would not be writable per Windows practices and guidelines (which put the application directory into read only mode for normal users).
TomTom
It wouldn't, it automatically stores the user.config file in a writeable directory, but the application could still use Properties.Settings to read and write the settings without needing to care about this.
ho1
You can find more information about where it's stored here: http://msdn.microsoft.com/en-us/library/ms379611%28VS.80%29.aspx
ho1
+1  A: 

Encrypt and Save it in the registry.

Dinesh
A: 

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)
}
abatishchev