当前位置:编程学习 > C#/ASP.NET >>

求助,winform登录窗口怎么实现记住密码?

--------------------编程问答-------------------- 加个文件判断是否选中了记住密码,比如ini,xml,txt 等 --------------------编程问答--------------------
引用 1 楼 deknight 的回复:
加个文件判断是否选中了记住密码,比如ini,xml,txt 等

不懂写,文件的读取写入还不会,C#选修课,没认真学。我想要个完整的例子来看看 --------------------编程问答-------------------- 临时的可以保存在内存,长久的可以保存在文件,数据库,注册表中,最好加密一下保存 --------------------编程问答-------------------- http://topic.csdn.net/u/20080831/10/337d2d10-d0b2-40d9-9bbb-1e56bf49556d.html
--------------------编程问答--------------------
引用 3 楼 bdmh 的回复:
临时的可以保存在内存,长久的可以保存在文件,数据库,注册表中,最好加密一下保存


这里只能给你思路,不可能帮你写程序的。 --------------------编程问答-------------------- 等待源码上来 .. . . --------------------编程问答--------------------
引用 3 楼 bdmh 的回复:
临时的可以保存在内存,长久的可以保存在文件,数据库,注册表中,最好加密一下保存

加密这个会,我就是想要一个例子来看看,网上找的太乱,没看懂 --------------------编程问答--------------------
引用 4 楼 deknight 的回复:
http://topic.csdn.net/u/20080831/10/337d2d10-d0b2-40d9-9bbb-1e56bf49556d.html

没看懂,很多东西都没学........C#是选修课,你懂的 --------------------编程问答-------------------- LZ你这...... --------------------编程问答-------------------- 很久以前做过一个类似的功能
是否自动登陆和是否记住密码

我是这样做的:
配置文件里 设置两个变量 
一个是:isAutoLogon(bool)用来表示是否自动登陆
另一个: autoLogonUser(string)存储自动登陆的用户名

如果客户选择了记住密码,isAutoLogon=true; autoLogonUser=userName;
当(isAutoLogon等于true)
{
    txtUserName等于autoLogonUser;
    txtPassword等于(从数据库读取密码,where userName=autoLogonUser);
}
--------------------编程问答-------------------- 进行序列化  

登录成功后,把用户名和密码封装成实体类,利用BinaryFormat进行序列化保存在本地文件中

等下次打开登录窗口,我进行反序列化。 --------------------编程问答-------------------- 这个东东有记住密码功能,可以看看源码去~[align=center]*****************************************
本内容使用CSDN小秘书回复
每天回帖即可得10分可用分!
*****************************************[/align] --------------------编程问答-------------------- 友情UP了。。。。。。。。。app.config。。。。。哎 --------------------编程问答--------------------
引用 10 楼 ttiimm11 的回复:
很久以前做过一个类似的功能
是否自动登陆和是否记住密码

我是这样做的:
配置文件里 设置两个变量 
一个是:isAutoLogon(bool)用来表示是否自动登陆
另一个: autoLogonUser(string)存储自动登陆的用户名

如果客户选择了记住密码,isAutoLogon=true; autoLogonUser=userName;
当(isAutoLogon等于t……

这种我看到之前有些帖子也讲过,但我想把密码存到bin文件里,密码是加密过的,存的时候是存了加密后的密码还有加密生成的key --------------------编程问答--------------------
引用 11 楼 remember_me 的回复:
进行序列化  

登录成功后,把用户名和密码封装成实体类,利用BinaryFormat进行序列化保存在本地文件中

等下次打开登录窗口,我进行反序列化。

不懂序列化...能给个例子吗 --------------------编程问答-------------------- 以前做过,用ComboBox控件来显示用户名。
窗体加载的时候,读取data.bin,把用户名加到ComboBox中。
在ComboBox的SelectedValueChanged事件中,获取comboBox1.SelectedItem.ToString(),
跟读取的用户名对比,取出密码。赋值给PassTextBox即可。
其他跟正常登录一样。 --------------------编程问答-------------------- 是否保存密码(复选框)和用户名,密码保存到INI文件

登陆时候,判断是否保存值,如果为真。读取INI中的用户名和密码。 --------------------编程问答--------------------
引用 16 楼 jy02349551 的回复:
以前做过,用ComboBox控件来显示用户名。
窗体加载的时候,读取data.bin,把用户名加到ComboBox中。
在ComboBox的SelectedValueChanged事件中,获取comboBox1.SelectedItem.ToString(),
跟读取的用户名对比,取出密码。赋值给PassTextBox即可。
其他跟正常登录一样。

能给个具体的文件示范下吗?序列化和反序列化还有文件操作都没学,我都是模仿着网上的例子做的 --------------------编程问答-------------------- 读取INI或XML中的数据好了。对应一个账号一个节点。 --------------------编程问答--------------------
引用 8 楼 a470649690 的回复:
引用 4 楼 deknight 的回复:

http://topic.csdn.net/u/20080831/10/337d2d10-d0b2-40d9-9bbb-1e56bf49556d.html

没看懂,很多东西都没学........C#是选修课,你懂的

c#我也是选修课 我还不是计算机相关专业的 零基础照样学的刻苦
纯粹的态度问题. --------------------编程问答--------------------
引用 20 楼 neo4026 的回复:
引用 8 楼 a470649690 的回复:
引用 4 楼 deknight 的回复:

http://topic.csdn.net/u/20080831/10/337d2d10-d0b2-40d9-9bbb-1e56bf49556d.html

没看懂,很多东西都没学........C#是选修课,你懂的

c#我也是选修课 我还不是计算机相关专业的 零基础照样学的刻苦
纯粹的态度……

C++是主修,C#不打算学太多,怕和C++混了............. --------------------编程问答-------------------- 不关语言的问题! --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace StudyWinform
{
    public partial class Form2 : Form
    {
        string dataPath = Application.StartupPath + "\\data.bin";

        private List<UserInfo> userlist = new List<UserInfo>();

        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (chkIsSave.Checked)
            {
                if (cboxUsername.SelectedItem.ToString() != "")
                {
                    UserInfo user = userlist.Find(t => t.UserName == cboxUsername.SelectedItem.ToString());
                    if (user != null)
                    {
                        user.Paaaword = tbPassword.Text;
                    }
                    File.WriteAllText(dataPath, "");
                    File.AppendAllText(dataPath, user.UserName + ";" + user.Paaaword + "\r\n", Encoding.UTF8);
                    for (int i = 0; i < userlist.Count; i++)
                    {
                        if (userlist[i].UserName != user.UserName)
                        {
                            File.AppendAllText(dataPath, userlist[i].UserName + ";" + userlist[i].Paaaword + "\r\n", Encoding.UTF8);
                        }
                    }
                }

            }
        }

        private void cboxUsername_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboxUsername.SelectedItem.ToString() != "")
            {
                UserInfo user = userlist.Find(t => t.UserName == cboxUsername.SelectedItem.ToString());
                if (user != null)
                {
                    tbPassword.Text = user.Paaaword;
                }
            }
        }

        private void Form2_Load(object sender, EventArgs e)
        {

            string[] data = File.ReadAllLines(dataPath);
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] != "" && data[i].Contains(";"))
                {
                    UserInfo user = new UserInfo();
                    user.UserName = data[i].Split(';')[0];
                    user.Paaaword = data[i].Split(';')[1];
                    cboxUsername.Items.Add(user.UserName);
                    userlist.Add(user);
                }
            }
        }
    }

    public class UserInfo
    {
        public string UserName { get; set; }
        public string Paaaword { get; set; }
    }
}






namespace StudyWinform
{
    partial class Form2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.tbPassword = new System.Windows.Forms.TextBox();
            this.cboxUsername = new System.Windows.Forms.ComboBox();
            this.chkIsSave = new System.Windows.Forms.CheckBox();
            this.btnLogin = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // tbPassword
            // 
            this.tbPassword.Location = new System.Drawing.Point(59, 70);
            this.tbPassword.Name = "tbPassword";
            this.tbPassword.Size = new System.Drawing.Size(121, 20);
            this.tbPassword.TabIndex = 0;
            this.tbPassword.UseSystemPasswordChar = true;
            // 
            // cboxUsername
            // 
            this.cboxUsername.FormattingEnabled = true;
            this.cboxUsername.Location = new System.Drawing.Point(59, 25);
            this.cboxUsername.Name = "cboxUsername";
            this.cboxUsername.Size = new System.Drawing.Size(121, 21);
            this.cboxUsername.TabIndex = 1;
            this.cboxUsername.SelectedValueChanged += new System.EventHandler(this.cboxUsername_SelectedValueChanged);
            // 
            // chkIsSave
            // 
            this.chkIsSave.AutoSize = true;
            this.chkIsSave.Location = new System.Drawing.Point(13, 126);
            this.chkIsSave.Name = "chkIsSave";
            this.chkIsSave.Size = new System.Drawing.Size(62, 17);
            this.chkIsSave.TabIndex = 2;
            this.chkIsSave.Text = "记住我";
            this.chkIsSave.UseVisualStyleBackColor = true;
            // 
            // btnLogin
            // 
            this.btnLogin.Location = new System.Drawing.Point(105, 122);
            this.btnLogin.Name = "btnLogin";
            this.btnLogin.Size = new System.Drawing.Size(75, 23);
            this.btnLogin.TabIndex = 3;
            this.btnLogin.Text = "登录";
            this.btnLogin.UseVisualStyleBackColor = true;
            this.btnLogin.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(10, 28);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(43, 13);
            this.label1.TabIndex = 4;
            this.label1.Text = "用户名";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(10, 73);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(43, 13);
            this.label2.TabIndex = 5;
            this.label2.Text = "密 码";
            // 
            // Form2
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(209, 160);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.btnLogin);
            this.Controls.Add(this.chkIsSave);
            this.Controls.Add(this.cboxUsername);
            this.Controls.Add(this.tbPassword);
            this.Name = "Form2";
            this.Text = "Form2";
            this.Load += new System.EventHandler(this.Form2_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TextBox tbPassword;
        private System.Windows.Forms.ComboBox cboxUsername;
        private System.Windows.Forms.CheckBox chkIsSave;
        private System.Windows.Forms.Button btnLogin;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
    }
}
--------------------编程问答--------------------
引用 23 楼 jy02349551 的回复:
C# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms……


VS 2008做的。 --------------------编程问答-------------------- --------------------编程问答-------------------- 写 ini 文件啊 --------------------编程问答-------------------- 把密码加密后保存到文件或者数据库中就可以了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,