开发者

Where to store: User connection information?

;) 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.


Encrypt and Save it in the registry.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜