【问题标题】:Store user credential存储用户凭证
【发布时间】:2014-08-05 09:55:49
【问题描述】:

我尝试在注册表编辑器中存储用户凭据。它成功了。

  RegistryKey key;
  key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\\XXX\\Credential");
  key.SetValue("Name", txtusername);
  key.SetValue("Password", password);
  key.Close();

如何在 wpf 应用程序的凭证管理器中安全地存储用户凭证?

【问题讨论】:

  • 什么凭证管理器?
  • 凭据管理器用于存储用户凭据。它安全地存储了用户密码。它位于控制面板中(控制面板\用户帐户和家庭安全\凭据管理器)。以下链接如何在“Windows 商店应用程序”的凭证管理器中存储用户凭证。 eren.ws/2013/10/21/…。我的问题是:如何在 wpf 应用程序的凭据管理器中存储用户凭据?

标签: c# wpf wpf-controls wpfdatagrid


【解决方案1】:

如果仅在应用程序内部使用凭据,则您可以对其进行加密并将其添加到您的 app.config 文件中。

创建一个连接字符串类型的应用程序设置并将其命名为 myconnectionstring

使用 Common.DbConnectionStringBuilder,您可以使用您的用户名和密码在要求用户输入它们的对话框后面构建“连接字符串”。

然后(在 VB 中)

        Dim config As System.Configuration.Configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None)
        Dim section As System.Configuration.ConnectionStringsSection = DirectCast(config.GetSection("connectionStrings"), System.Configuration.ConnectionStringsSection)

        section.ConnectionStrings(My.Settings.ToString & ".myconnectionstring").ConnectionString = ConnectionString

        section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")

        config.Save(System.Configuration.ConfigurationSaveMode.Modified)

        System.Configuration.ConfigurationManager.RefreshSection("connectionStrings")

这应该将其加密保存在 app.config 中

当读回数据时,.Net 会为您处理所有的解密。

只需创建另一个 Common.DbConnectionStringBuilder 对象,将其连接字符串属性分配给Configuration.ConfigurationManager.ConnectionStrings(My.Settings.ToString & ".myconnectionstring").connectionstring,然后读取您需要的字段。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 2013-05-17
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    相关资源
    最近更新 更多