存储"记得我"信息在本地的C#(总newbeginner) [英] Storing "remember me" information locally c# (total newbeginner)

查看:167
本文介绍了存储"记得我"信息在本地的C#(总newbeginner)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前就开始在C#编程几天,所以我在这是一个总newbeginner。根据我在其他语言的经验,我发现它有点简单。

I started programming in c# for a few days ago, so I am a total newbeginner at this. Based on my experience in other languages, I found it somewhat "simple".

我建在那里用户可以登录到我的应用程序,这是工作的系统。我希望有一个记住我 - 设置在那里的信息被存储在本地。什么是做到这一点的最好方法是什么? 。我只保存用户名和密码散列

I am building a system where users are logging in to my application, which is working. I want to have a "remember me"-setting where the information is stored locally. What is the best way to do this? I'll only save the username and the password-hash.

编辑:这是一个桌面应用程序。登录信息被发送到一个PHP脚本简单地使用的HttpWebRequest

This is a desktop-application. The login-information is sent to a php-script simply using HttpWebRequest

推荐答案

您可以使用 ConfigurationManager中类来管理你的。应用程序的设置。

You can use the ConfigurationManager Class to manage your application's settings.

您可以使用此功能将新的密钥添加到您的配置文件:

you can use this function to add new Keys to your configuration file:

public bool setSetting(string pstrKey, string pstrValue)
{
    Configuration objConfigFile =
        ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    bool blnKeyExists = false;

    foreach (string strKey in objConfigFile.AppSettings.Settings.AllKeys)
    {
        if (strKey == pstrKey)
        {
            blnKeyExists = true;
            objConfigFile.AppSettings.Settings[pstrKey].Value = pstrValue;
            break;
        }
    }
    if (!blnKeyExists)
    {
        objConfigFile.AppSettings.Settings.Add(pstrKey, pstrValue);
    }
    objConfigFile.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("appSettings");
    return true;
}



,然后保存您的用户名(例如)

and then save up your username (for example)

setSetting("username", usernameTextBox.Text);

在您的应用程序启动时,可以读取先前从 ConfigurationManager中

Once your application starts up, you can read the information you saved earlier from your ConfigurationManager

usernameTextBox.Text = ConfigurationManager.AppSettings["username"];

这篇关于存储"记得我"信息在本地的C#(总newbeginner)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆