c#.net怎么保存用户名和密码,点击保存密码下次登陆可以直接进去

解决方案 »

  1.   

    详细一点的,cookies我不怎么会用
      

  2.   

    正解!所有的保存密码都是用的cookies
      

  3.   

    就是啊楼主你是要winform还是webform,winform就把登录名和密码写到数据库
    webform就写到cookies里面!cookies方面的这里也许有用
    http://www.bitscn.com/dotnet/c/200803/130948.html
      

  4.   

    ........webfrom需要流winfrom需要数据库...
      

  5.   

    winform可以建数据表来存储用户名和密码信息的表,
    然后建议把默认用户用配置文件来记录,在窗体Load时读出来并自动填入,用户登陆时回车就OK了。下面分别给两个代码吧。
    (一)保存用户名和密码到数据库
    记得在引用部分加上:
    using System.Data.SqlClient;
          private void button1_Click(object sender, EventArgs e)
            {
                string userName = textBox1.Text            string userPswd = textBox2.Text            string constr = "Server=(Local);User Id=Sa;Pwd=;DataBase=HSSN";
                SqlConnection con = new SqlConnection(constr);
                con.Open();
                string instr;
                instr = "insert into userinfo(name,pswd) values (" + "'" + userName + "'" + "," + "'" + userPswd + "'" + ")";
                SqlCommand cmd = new SqlCommand(instr, con);
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }            con.Close();
            }(二)下面是一个Iin文件读写的类
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.IO;namespace IniOperator
    {
        public class INIClass
        {
            public string inipath;        [DllImport("kernel32")]
            private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
            [DllImport("kernel32")]
            private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);        public INIClass(string INIPath)
            {
                inipath = INIPath;
            }
            ///
            /// 写入INI文件
            ///
            /// 项目名称(如 [TypeName] )
            /// 键
            /// 值
            public void IniWriteValue(string Section, string Key, string Value)
            {
                WritePrivateProfileString(Section, Key, Value, this.inipath);
            }
            ///
            /// 读出INI文件
            ///
            /// 项目名称(如 [TypeName] )
            /// 键
            public string IniReadValue(string Section, string Key)
            {
                StringBuilder temp = new StringBuilder(500);
                int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
                return temp.ToString();
            }
            ///
            /// 验证文件是否存在
            ///
            /// 布尔值
            public bool ExistINIFile()
            {
                return File.Exists(inipath);
            } 
        } 
    }
    (三、)读用上面的类读定Ini文件
    private INIClass inic;
    inic = new INIClass("写上你的文件名");
    //写入
                if (inic.ExistINIFile())
                {
                    try
                    {
                        inic.IniWriteValue(textBox2.Text, textBox3.Text, textBox4.Text);
                    }
                    catch (Exception ex)
                    {
                         MessageBox.Show(ex.Message);
                    }
                }
    //写入ini文件
                try
                {
                    textBox4.Text = inic.IniReadValue(textBox2.Text, textBox3.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
      

  6.   

    如果是登陆的话,请把用户的个人设置序列化为文件(用户个人配置文件 - Profile)