http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4996|回复: 6

[Winform] 记住密码(求代码实现)

[复制链接]
发表于 2014-8-22 19:51:22 | 显示全部楼层 |阅读模式
求代码:首先生成一个文件用于保存密码,记住密码并对密码加密。求详细代码

登录

登录


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-8-23 00:21:43 | 显示全部楼层
写出去。至于加密,自己写一个或者百度下。
 楼主| 发表于 2014-8-23 17:50:08 | 显示全部楼层
百度那些都配套不上,代码该怎么写呀?
 楼主| 发表于 2014-8-23 17:51:08 | 显示全部楼层
这个是用来加密的类:

        using System;  
        using System.Collections.Generic;  
        using System.Xml.Linq;  
        using System.Text;  
        using System.Security.Cryptography;  
        using System.IO;

namespace quanyuntong  
        {  
            public class MyEncrypt  
            {  
                private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };  
                private static string encryptKey = "abcdefgh";  
                /// <summary>  
                /// DES加密字符串  
                /// </summary>  
                /// <param name="encryptString">待加密的字符串</param>  
                /// <param name="encryptKey">加密密钥,要求为8位</param>  
                /// <returns>加密成功返回加密后的字符串,失败返回源串</returns>  
                public static string EncryptDES(string encryptString)  
                {  
                    try  
                    {  
                        byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));  
                        byte[] rgbIV = Keys;  
                        byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);  
                        DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();  
                        MemoryStream mStream = new MemoryStream();  
                        CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);  
                cStream.Write(inputByteArray, 0, inputByteArray.Length);  
                        cStream.FlushFinalBlock();  
                        return Convert.ToBase64String(mStream.ToArray());  
            }  
                    catch  
                    {  
                        return encryptString;  
                    }  
                }  
                /// <summary>  
                /// DES解密字符串  
                /// </summary>  
                /// <param name="decryptString">待解密的字符串</param>  
                /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>  
                /// <returns>解密成功返回解密后的字符串,失败返源串</returns>  
                public static string DecryptDES(string decryptString)  
                {  
                    try  
                    {  
                        byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey);  
                byte[] rgbIV = Keys;  
                        byte[] inputByteArray = Convert.FromBase64String(decryptString);  
                        DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();  
                        MemoryStream mStream = new MemoryStream();  
                        CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);  
                        cStream.Write(inputByteArray, 0, inputByteArray.Length);  
                        cStream.FlushFinalBlock();  
                        return Encoding.UTF8.GetString(mStream.ToArray());  
            }  
                    catch  
            {  
                        return decryptString;  
                    }  
                }  
            }  
        }
 楼主| 发表于 2014-8-25 00:25:55 | 显示全部楼层
本帖最后由 龍游天下 于 2014-8-25 00:27 编辑

以下代码还是实现不了,高手帮帮修改一下呀。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb; //Access的命名空间
using CCWin;
using CCWin.SkinControl;
using CCWin.SkinClass;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;//引用序列化类


namespace quanyuntong
{
    public partial class Form1 : CCSkinMain
    {
        //static public string usmen;//用户名,做用于保存
        //static public string uspass;//密码,保存
        public Form1()
        {
            InitializeComponent();//完成窗体的初始化工作
        }

        //窗体加载
        List<User> aalist;//声明一个用户的泛型集合
        private void Form1_Load(object sender, EventArgs e)
        {
            if (File.Exists("userInfo.txt"))//查检文件是否存在,存在是true则花括号内的程序
            {
                FileStream fs = new FileStream("userInfo.txt", FileMode.Open, FileAccess.Read);
                BinaryFormatter bf = new BinaryFormatter();//创建一个序列化和反序列化类的对象
                aalist = (List<User>)bf.Deserialize(fs);//调用反序列化方法,从文件userInfo.txt中读取对象信息
                for (int i = 0; i < aalist.Count; i++)
                {
                    if (i == 0 && aalist.LoginName != "")
                    {
                        this.skinCheckBox1.Checked = true;
                        this.txt_Pwd.Text = aalist.LoingPassword;
                    }
                    this.txt_Name.Text = aalist.LoginName.ToString();
                }
                fs.Close();//关闭文件流
            }
            else
            {
                aalist = new List<User>();
                txt_Name.Text = "";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {           
            this.progressBar1.Style = ProgressBarStyle.Marquee;//进度条上的幕来回运动
            //这里写入上面的判断语句,假如!pdyj()为false则弹出提示窗
            if (txt_Name.Text == "")
            {
                MessageBox.Show("用户名称不能为空!");
                txt_Name.Focus();
                return;
            }
            if (txt_Pwd.Text == "")
            {
                MessageBox.Show("登录密码不能为空!");
                txt_Pwd.Focus();
                return;
            }
            //创建连接字符串
            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"rovider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\软件\quanyuntong1.2\quanyuntong\database\data_qyt.mdbersist Security Info=True";
            //当创建好了连接到Access数据库后就开始打开连接
            conn.Open();
            //打开了连接后我们就开始用查询语句来查询数据库表的内容,现在做的登录窗就要用到用户名和密码来作判断
            //if语句判断用户名和密码是否正确,然后用查询语句开始查询,错的就做了提示,正确就进入数据库
            //SQL查询语句,做判断表的用户名和密码
            string Access = "select username,password from userInfo where username='" + txt_Name.Text + "'and password='" + txt_Pwd.Text + "'";
            //查询语句写好了就用到
            OleDbCommand cmd = new OleDbCommand(Access, conn);//执行SQL查询
            OleDbDataReader hyw = cmd.ExecuteReader();//执行命令,返回DataReader类的一个对象
            //连接创建命令做好了接下来就开始有if来判断语句
            if (hyw.Read())//当有数据读取时
            {
                string loginName = this.txt_Name.Text.Trim();//将用户名先保存在变量中
                User usmen;               
                //在构造中变量就作为判断
                if (this.skinCheckBox1.Checked == true) //假如记住密码被选中
                {
                    string newPwd = MyEncrypt.EncryptDES(this.txt_Pwd.Text.Trim());//对密码进行加密
                    usmen = new User(loginName, newPwd);

                    //MessageBox.Show("您选中了记住密码");
                    //uspass = MyEncrypt.EncryptDES(this.txt_Pwd.Text.Trim());//对密码进行加密
                    //StreamWriter streamwriter = new StreamWriter("userInfo.txt", true);//可以对文件进行修改操作
                    //streamwriter.WriteLine(usmen);
                    //streamwriter.WriteLine(uspass);
                    //streamwriter.Close();
                }
                else
                    usmen = new User(loginName, "");//否则只插入一个用户名到用户集合中,密码设为空
                    //aalist.Insert(0, usmen);

                ////连接成功就弹出提示窗                 
                //MessageBox.Show("连接成功,正在载入数据…………");            
                //验证正确就进入下一个窗体
                Form2 f2 = new Form2(this);
                f2.usmen = Convert.ToString(usmen);
                f2.Show();
            }
            else
            {
                //信息错误,判断条件不成立
                MessageBox.Show("用户名和密码错误,请重新输入");
            }
            conn.Close();
        }
           
           
    }
}
 楼主| 发表于 2014-8-27 20:59:42 | 显示全部楼层
没人回答,我自己搞定了。
发表于 2016-12-14 20:43:40 | 显示全部楼层
我有的,,,不过有点难度。博客园看到的,测试通过,通过INI机制实现的,我给你demo吧
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-25 02:28

© 2014-2021

快速回复 返回顶部 返回列表