Rumah > pangkalan data > tutorial mysql > 账号密码管理系统Access版本

账号密码管理系统Access版本

WBOY
Lepaskan: 2016-06-07 15:48:52
asal
1707 orang telah melayarinya

哈哈,花了我整整五天时间, 账号 密码 管理 系统 软件终于成功编写完成了。由于我的各大论坛的 账号 密码 特别多,记性又不好。所以一直以来都想要这么一个软件的,但是以前学习的都是面向过程的编程语言,一直无法实现这个想法。这个暑假为了做一个程序项

 

       哈哈,花了我整整五天时间,账号密码管理系统软件终于成功编写完成了。由于我的各大论坛的账号密码特别多,记性又不好。所以一直以来都想要这么一个软件的,但是以前学习的都是面向过程的编程语言,一直无法实现这个想法。这个暑假为了做一个程序项目,对记事本实现图形用户界面增删改查操作,所以开始学习C#编程。在花了整整二十天学习Winform编程和研究文件读写流(大多数时间在学习文件读写流上,Winform编程也就学会了几个常用的控件,文件读写流这个边读边写刚开始不会,特别蛋疼),好在经过一番努力学习后终于实现了。在完成这个后,突然想起一直以来想要的这个软件,于是开始动手编写,在快开学的这五天内,简单匆忙简单学习了下Winform数据库编程(账号密码想法是放在数据库里比较好)。编写这个软件刚开始使用的SQL server数据库,但是当我花了三天左右完成时,才发现竟然蛋疼的无法脱机使用。查了资料后知道了用Access数据库可以实现脱机使用。而且之前用过的御剑、啊D、明小子之类渗透软件也大都是用的Access数据库,可移植性很好。因此只好开始又想法将SQL server更换成Access数据库。不停地在百度上转啊转,搞了半天才知道更换也很简单,只要将连接数据库语句更换下,再把Sql换成OleDb即可。更换期间也出了很多未知的蛋疼的问题,编译器查不出来哪里的问题,代码页看出出来哪里不对。搞了半天才知道原来数据库名称和字段名称不小心和access数据库中关键词冲突了。不过不管怎么说,终于搞定了。但是完成后安全性还是个问题,那么多账号密码明文存放access数据库,那也太不安全了。因此又开始给程序增加加密算法。菜鸟学艺不精,而且时间有限,只好直接引用现成的加密算法了,程序界面登陆不需要查看账号密码,因此最后考虑后采用了单向加密的MD5 32位加密算法加密,而数据库内存储的账号密码信息信息还需要显示出来,而MD5虽然安全但是不可逆,只能加密对比后台登陆使用,因此最终采用了DES加密算法和MD5混合加密的方法,当然加密算法是我copy的,我是菜鸟还没那个本事自己编写。

     嘿嘿。废话说了一大堆,现在开始言归正传。

  由于在下 的各种论坛账号密码特别多,记性又不好,为了方便账号密码管理而编写的这个小软件。

使用说明:

1. 本程序由本人星云用Winform编程+Access数据库编写;(程序运行需安装有.net2.0环境和access软件)

2.登陆界面有四次登陆机会,连续四次登陆四次错误,程序将会锁定禁止使用,防止密码被暴力破解。

3.解锁方法:

用户名+秘钥:用户提供修改后的用户名配合本人在程序中设置的一个秘钥才可以解锁。(缺一不可。)

4.登陆界面账号密码初始密码都为:root,采用不可逆的单向加密MD5加密算法进行加密.

5.为了账号安全,请登陆后后立即点击系统维护按钮,进入登陆密码修改界面。

6.为了防止直接打开ACCESS数据库文件,对此打开进行了数据库密码设置,密码采用不可逆的MD5加密。

7.关于软件是否开源问题,考虑后觉得“交流即分享,分享才能进步“,因此最终决定开源,况且这也没什么技术含量。

8.源码公开后软件账号密码安全性问题,在下决定在源码中对程序中涉及到的关键敏感密码处加以更改。

程序截图:

账号密码管理系统Access版本

查询方式有两种,下拉菜单查询以及搜索查询。

账号密码管理系统Access版本

基本功能添加修改删除

账号密码管理系统Access版本

系统维护界面:

账号密码管理系统Access版本

 软件下载地址:http://pan.baidu.com/s/1i3uuCKH 密码:7u2y

文章中的公开项目源码下载:http://pan.baidu.com/s/1qWNS3Bu 密码:s05u

程序源码:

Form窗体1如下:

<span>using</span><span> System;
</span><span>using</span><span> System.Windows.Forms;
</span><span>using</span><span> System.Data.OleDb;
</span><span>using</span><span> System.Security.Cryptography;
</span><span>using</span><span> System.Text;

</span><span>namespace</span><span> <strong>账号</strong><strong>密码</strong><strong>管理</strong><strong>系统</strong>1._0
{
    </span><span>public</span> <span>partial</span> <span>class</span><span> Form1 : Form
    {
        </span><span>public</span><span> Form1()
        {
            InitializeComponent();
        }

        </span><span>//</span><span>登陆错误时调用此函数:错误次数加一</span>
        <span>private</span> <span>void</span><span> IncErrortimes()
        {
            </span><span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建数据库命令语句,更新错误次数加一</span>
                    <span>using</span> (OleDbCommand UpdateCmd =<span> conn.CreateCommand())
                    {
                        UpdateCmd.CommandText </span>= <span>"</span><span>update T_system Set Errortimes=Errortimes+1 where sys_username=@name</span><span>"</span><span>;
                        UpdateCmd.Parameters.Add(</span><span>new</span> OleDbParameter(<span>"</span><span>name</span><span>"</span><span>, textBox1.Text));
                        UpdateCmd.ExecuteNonQuery();

                    }
                }
            }
        }

        </span><span>//</span><span>登陆成功时调用此函数:重置错误次数</span>
        <span>private</span> <span>void</span><span> ResetErrotimes()
        {
            </span><span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建数据库命令语句</span>
                    <span>using</span> (OleDbCommand UpdateCmd =<span> conn.CreateCommand())
                    {
                        UpdateCmd.CommandText </span>= <span>"</span><span>update T_system Set Errortimes=0 where sys_username=@name</span><span>"</span><span>;
                        UpdateCmd.Parameters.Add(</span><span>new</span> OleDbParameter(<span>"</span><span>name</span><span>"</span><span>, textBox1.Text));
                        UpdateCmd.ExecuteNonQuery();

                    }
                }
            }
        }

        </span><span>//</span><span>秘钥清除使用</span>
        <span>private</span> <span>void</span><span> RecoverErrotimes()
        {
            </span><span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句,重置错误次数为0</span>
                    <span>using</span> (OleDbCommand UpdateCmd =<span> conn.CreateCommand())
                    {
                        UpdateCmd.CommandText </span>= <span>"</span><span>update T_system Set Errortimes=0 where sys_username=@name</span><span>"</span><span>;
                        UpdateCmd.Parameters.Add(</span><span>new</span> OleDbParameter(<span>"</span><span>name</span><span>"</span><span>, textBox1.Text));
                        UpdateCmd.ExecuteNonQuery();

                    }

                    </span><span>//</span><span>创建SQL命令语句,恢复默认<strong>密码</strong>为root</span>
                    <span>using</span> (OleDbCommand UpdateCmd =<span> conn.CreateCommand())
                    {
                        UpdateCmd.CommandText </span>= <span>"</span><span>update T_system Set sys_password='63a9f0ea7bb98050796b649e85481845' where sys_username=@name</span><span>"</span><span>;
                        UpdateCmd.Parameters.Add(</span><span>new</span> OleDbParameter(<span>"</span><span>name</span><span>"</span><span>, textBox1.Text));
                        UpdateCmd.ExecuteNonQuery();

                    }
                }
            }
        }

        </span><span>//</span><span>当单击"登陆"按钮时执行以下事件处理程序</span>
        <span>private</span> <span>void</span> button1_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        cmd.CommandText </span>= <span>"</span><span>select * from T_system where sys_username=@name</span><span>"</span><span>;
                        cmd.Parameters.Add(</span><span>new</span> OleDbParameter(<span>"</span><span>name</span><span>"</span><span>, GetMD5(textBox1.Text)));

                        </span><span>//</span><span>读取数据库查询结果进行用户名和<strong>密码</strong>判断</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span> (reader.Read())<span>//</span><span>用户名输入正确</span>
<span>                            {
                                </span><span>int</span> errortimes = reader.GetInt32(reader.GetOrdinal(<span>"</span><span>Errortimes</span><span>"</span><span>));
                                </span><span>if</span> (errortimes > <span>3</span><span>)
                                {

                                    </span><span>if</span> (textBox2.Text == <span>"</span><span>解锁 秘钥字符串,此处已经修改</span><span>"</span><span>)
                                    {
                                        RecoverErrotimes();
                                        MessageBox.Show(</span><span>"</span><span>程序解锁成功,程序即将重新启动!</span><span>"</span><span>);
                                        Application.Exit();
                                        </span><span>return</span><span>;
                                    }
                                    </span><span>else</span><span>
                                    {
                                        MessageBox.Show(</span><span>"</span><span><strong>密码</strong>错误次数太多,程序已经被锁定禁用!</span><span>"</span><span>);
                                        Application.Exit();
                                        </span><span>return</span><span>;

                                    }
                                }
                                </span><span>string</span> dbpassword = reader.GetString(reader.GetOrdinal(<span>"</span><span>sys_password</span><span>"</span><span>));
                                </span><span>if</span> (dbpassword == GetMD5(textBox2.Text))<span>//</span><span>登陆成功!</span>
<span>                                {
                                    ResetErrotimes();</span><span>//</span><span>登陆成功,错误次数清零</span>
                                    Form2 fm2 = <span>new</span><span> Form2();
                                    </span><span>this</span><span>.Hide();
                                    fm2.Show(); 
                                }
                                </span><span>else</span><span>
                                {
                                    MessageBox.Show(</span><span>"</span><span>登陆失败!</span><span>"</span><span>);
                                    IncErrortimes();
                                }
                            }
                            </span><span>else</span>   <span>//</span><span>用户输入错误</span>
<span>                            {
                                MessageBox.Show(</span><span>"</span><span>用户名不存在!</span><span>"</span><span>);

                            }
                        }
                    }
                }
            }
        }
        </span><span>//</span><span>MD5加密算法</span>
        <span>public</span> <span>static</span> <span>string</span> GetMD5(<span>string</span><span> str)
        {
            MD5 md5 </span>=<span> MD5.Create();
            </span><span>byte</span>[] buffer =<span> Encoding.Default.GetBytes(str);
            </span><span>byte</span>[] MD5buffer =<span> md5.ComputeHash(buffer);
            </span><span>string</span> strnew = <span>""</span><span>;
            </span><span>for</span> (<span>int</span> i = <span>0</span>; i )
            {
                strnew += MD5buffer[i].ToString(<span>"</span><span>x2</span><span>"</span><span>);
            }
            </span><span>return</span><span> strnew;
        }
        </span><span>//</span>
        <span>private</span> <span>void</span> label4_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>string</span> information = <span>"</span><span>\t欢迎使用<strong>账号</strong><strong>密码</strong><strong>管理</strong><strong>系统</strong>\n\n1.初始<strong>账号</strong>:root <strong>密码</strong>: root \n\n2.登陆后请立即修改登陆<strong>账号</strong>和<strong>密码</strong>\n\n3.<strong>账号</strong>和<strong>密码</strong>打死也不能忘记和告诉其他人\n\n4.连续登陆错误次数多于4次,此程序将会被锁定禁用\n\n5.解锁需要用户和作者合作才能解锁成功!\n\n6.用户需提供用户名,作者提供清除错误次数秘钥,\n\n还原默认<strong>密码</strong>合作才能完成\n\n6.为了防止<strong>密码</strong>暴力破解以及<strong>系统</strong>锁定后无法使用,\n\n作者掌握清除错误次数和还原<strong>系统</strong>默认<strong>密码</strong>秘钥,但无法修改登陆<strong>账号</strong>\n\n因此如果登陆<strong>账号</strong>也忘记,作者也回天无力。\n\n7.联系作者:xingyun2684@gmail.com</span><span>"</span><span>;
            MessageBox.Show(</span><span>null</span>, information, <span>"</span><span>使用说明:</span><span>"</span><span>);

        }

        </span><span>//</span><span>当单击"重置"按钮时执行以下事件处理程序</span>
        <span>private</span> <span>void</span> button2_Click(<span>object</span><span> sender, EventArgs e)
        {
            textBox1.Text </span>= <span>""</span><span>;
            textBox2.Text </span>= <span>""</span><span>;
        }
    }
}</span>
Salin selepas log masuk

Form2窗体源码:

<span>using</span><span> System;
</span><span>using</span><span> System.Windows.Forms;
</span><span>using</span><span> System.Data.SqlClient;
</span><span>using</span><span> System.Data.OleDb;
</span><span>using</span><span> System.Security.Cryptography;
</span><span>using</span><span> System.Text;
</span><span>using</span><span> System.IO;

</span><span>namespace</span><span> <strong>账号</strong><strong>密码</strong><strong>管理</strong><strong>系统</strong>1._0
{
    </span><span>public</span> <span>partial</span> <span>class</span><span> Form2 : Form
    {
        </span><span>public</span><span> Form2()
        {
            InitializeComponent();

            </span><span>//</span><span>combox1 下拉条内容初始化</span>
            <span>/*</span><span>********************************************************</span><span>*/</span>
           
            <span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句</span>
                        cmd.CommandText = <span>"</span><span>select account_type from T_users</span><span>"</span><span>;
                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>while</span><span> (reader.Read())
                            {
                                comboBox1.Items.Add((reader.GetString(reader.GetOrdinal(</span><span>"</span><span>account_type</span><span>"</span><span>))));
                            }
                        }
                    }
                }
            }
            </span><span>/*</span><span>*******************************************************</span><span>*/</span><span>
        }

        </span><span>/*</span><span>************************************************************************
               * 
               *               算法加密模块 
               * 
               * 登陆<strong>账号</strong><strong>密码</strong>采用md5加密算法进行加密。
               * 
               * 信息内容采用 DES加密算法+MD5混合加密算法
               *  
               * 所有<strong>账号</strong>信息将调用此函数进行数据加密
               *
               *  调用方法:EncryptDES(string 明文字符串, string 秘钥字符串);
               *
               *            DecryptDES(string 密文字符串, string 秘钥字符串);
               *                                     
               * ********************************************************************</span><span>*/</span>
       
        <span>//</span><span>DES普通加密解密算法
        
        </span><span>//</span><span> DES加密字符串</span>
        <span>private</span> <span>static</span> <span>byte</span>[] Keys = { <span>0x12</span>, <span>0x34</span>, <span>0x56</span>, <span>0x78</span>, <span>0x90</span>, <span>0xAB</span>, <span>0xCD</span>, <span>0xEF</span><span> };

        </span><span>/*</span><span>***********************************************************************
         *  
         * 解密函数:DecryptDES(string 密文字符串, string 秘钥字符串);
         * 
         * encryptString       待加密的字符串
         * 
         * encryptKey          加密密钥,要求为8位
         * 
         * 加密返回值        加密后的字符串,失败返回源串 
         * 
         * **************************************************************************</span><span>*/</span>
        <span>public</span> <span>static</span> <span>string</span> EncryptDES(<span>string</span> encryptString, <span>string</span><span> encryptKey)
        {
            </span><span>try</span><span>
            {
                </span><span>byte</span>[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(<span>0</span>, <span>8</span><span>));
                </span><span>byte</span>[] rgbIV =<span> Keys;
                </span><span>byte</span>[] inputByteArray =<span> Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP </span>= <span>new</span><span> DESCryptoServiceProvider();
                MemoryStream mStream </span>= <span>new</span><span> MemoryStream();
                CryptoStream cStream </span>= <span>new</span><span> CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, </span><span>0</span><span>, inputByteArray.Length);
                cStream.FlushFinalBlock();
                </span><span>return</span><span> Convert.ToBase64String(mStream.ToArray());
            }
            </span><span>catch</span><span>
            {
                </span><span>return</span><span> encryptString;
            }
        }

        </span><span>/*</span><span> ********************************************************************************</span><span>*/</span>

        <span>/*</span><span> DES解密函数 DecryptDES(string 密文字符串, string 秘钥字符串);
         * 
         *        decryptString : 待解密的字符串
         * 
         *           decryptKey :   解密密钥,要求为8位,和加密密钥相同
         *        
         *                返回值:      解密成功返回解密后的字符串,失败返源串
         *
         ***********************************************************************************</span><span>*/</span>
        <span>public</span> <span>static</span> <span>string</span> DecryptDES(<span>string</span> decryptString, <span>string</span><span> decryptKey)
        {
            </span><span>try</span><span>
            {
                </span><span>byte</span>[] rgbKey =<span> Encoding.UTF8.GetBytes(decryptKey);
                </span><span>byte</span>[] rgbIV =<span> Keys;
                </span><span>byte</span>[] inputByteArray =<span> Convert.FromBase64String(decryptString);
                DESCryptoServiceProvider DCSP </span>= <span>new</span><span> DESCryptoServiceProvider();
                MemoryStream mStream </span>= <span>new</span><span> MemoryStream();
                CryptoStream cStream </span>= <span>new</span><span> CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, </span><span>0</span><span>, inputByteArray.Length);
                cStream.FlushFinalBlock();
                </span><span>return</span><span> Encoding.UTF8.GetString(mStream.ToArray());
            }
            </span><span>catch</span><span>
            {
                </span><span>return</span><span> decryptString;
            }
        }
        </span><span>//</span><span>添加数据</span><span>
/*</span><span>************************************************************************</span><span>*/</span>
        <span>private</span> <span>void</span> button1_Click(<span>object</span><span> sender, EventArgs e)
        {
           </span><span>//</span><span> 1. 判断是否数据库内已经有该条记录</span>
        <span>/*</span><span>***************************************************************</span><span>*/</span>
            <span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改。</span><span>"</span><span>;
            {
                    </span><span>using</span> (OleDbConnection conn2 = <span>new</span><span> OleDbConnection(connectionString)) 
                    {
                    conn2.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn2.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句加密后查询</span>
                        cmd.CommandText = <span>"</span><span>select account_type from T_users where account_type='</span><span>"</span> + textBox1.Text + <span>"</span><span>'</span><span>"</span><span>;
                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span> (reader.Read())<span>//</span><span>如果存在</span>
<span>                            {
                                MessageBox.Show(</span><span>"</span><span>对不起,同一类型的<strong>账号</strong>只能添加一次!</span><span>"</span>, <span>"</span><span>添加失败提示</span><span>"</span><span>);

                                </span><span>//</span><span>清空内容</span>
                                textBox1.Text = <span>""</span><span>;
                                textBox2.Text </span>= <span>""</span><span>;
                                textBox3.Text </span>= <span>""</span><span>;
                                textBox4.Text </span>= <span>""</span><span>;
                                textBox5.Text </span>= <span>""</span><span>;
                                </span><span>return</span><span>;
                            }
                            </span><span>else</span> <span>//</span><span>数据库中不存在此类型<strong>账号</strong>则将其添加</span>
<span>                            {

                                </span><span>//</span><span>  更新combox 下拉选项 </span>
<span>                                comboBox1.Items.Add(textBox1.Text);
                                </span><span>//</span><span>添加信息插入到数据库内  </span>
                                <span>/*</span><span>*********************************************************************</span><span>*/</span>
                                <span>//</span><span>与数据库建立连接</span>
                                <span>string</span> connectionString2 = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
                                {
                                    </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString2))
                                    {
                                        conn.Open();</span><span>//</span><span>打开连接

                                        </span><span>//</span><span>创建SQL命令语句,添加内容都将会调用MD5算法进行加密,然后保存到数据库内。</span>
                                        <span>using</span> (OleDbCommand insert_cmd =<span> conn.CreateCommand())
                                        {
                                            </span><span>//</span><span>SQL查询语句</span>
                                            insert_cmd.CommandText = <span>"</span><span>insert into T_users (account_type,account_website,account_username,account_password)values('</span><span>"</span> + textBox1.Text + <span>"</span><span>','</span><span>"</span> + EncryptDES(textBox2.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>','</span><span>"</span> + EncryptDES(textBox3.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>','</span><span>"</span> + EncryptDES(textBox4.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>');</span><span>"</span><span>;
                                            insert_cmd.ExecuteNonQuery();
                                        }

                                    }
                                    </span><span>/*</span><span>************************************************</span><span>*/</span><span>
                                    textBox1.Text </span>= <span>""</span><span>;
                                    textBox2.Text </span>= <span>""</span><span>;
                                    textBox3.Text </span>= <span>""</span><span>;
                                    textBox4.Text </span>= <span>""</span><span>;
                                    textBox5.Text </span>= <span>""</span><span>;
                                    MessageBox.Show(</span><span>"</span><span>插入成功!</span><span>"</span>, <span>"</span><span>插入提示</span><span>"</span><span>);
                                }
                            }
                        }
                    }
                }
            }
            }
        
</span><span>/*</span><span>**********************************************************************</span><span>*/</span>

        <span>//</span><span>修改更新数据实现</span><span>
/*</span><span>*********************************************************</span><span>*/</span>
        <span>private</span> <span>void</span> button2_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>//</span><span>判断是否库中是否有此记录,有才可以修改。</span>
            <span>/*</span><span>**********************************************************</span><span>*/</span>
            <span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句</span>
                        cmd.CommandText = <span>"</span><span>select account_type from T_users where account_type='</span><span>"</span> + textBox1.Text + <span>"</span><span>';</span><span>"</span><span>;
                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span><span> (reader.Read())
                            {
                                </span><span>//</span><span>与数据库建立连接</span>
                                <span>string</span> connectionString2 = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
                                {
                                    </span><span>using</span> (OleDbConnection conn2 = <span>new</span><span> OleDbConnection(connectionString2))
                                    {
                                        conn2.Open();</span><span>//</span><span>打开连接

                                        </span><span>//</span><span>创建SQL命令语句</span>
                                        <span>using</span> (OleDbCommand modify_cmd =<span> conn2.CreateCommand())
                                        {
                                            </span><span>//</span><span>SQL查询语句</span>
                                            modify_cmd.CommandText = <span>"</span><span>update T_users set account_website='</span><span>"</span> + EncryptDES(textBox2.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>',account_username='</span><span>"</span> + EncryptDES(textBox3.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>',account_password='</span><span>"</span> + EncryptDES(textBox4.Text, <span>"</span><span>信息md5加密字符串</span><span>"</span>) + <span>"</span><span>' where account_type='</span><span>"</span> + textBox1.Text + <span>"</span><span>';</span><span>"</span><span>;
                                            modify_cmd.ExecuteNonQuery();

                                            </span><span>//</span><span>修改成功清空内容</span>
                                            textBox1.Text = <span>""</span><span>;
                                            textBox2.Text </span>= <span>""</span><span>;
                                            textBox3.Text </span>= <span>""</span><span>;
                                            textBox4.Text </span>= <span>""</span><span>;
                                            textBox5.Text </span>= <span>""</span><span>;
                                            MessageBox.Show(</span><span>"</span><span>修改成功!</span><span>"</span>, <span>"</span><span>修改提示</span><span>"</span><span>);
                                        }
                                    }
                                }
                            }
                            </span><span>else</span><span>
                            {
                                MessageBox.Show(</span><span>"</span><span>数据库内没有该<strong>账号</strong>类型,无法修改!</span><span>"</span>, <span>"</span><span>修改失败提示</span><span>"</span><span>);
                                </span><span>return</span><span>;
                            }
                        }
                    }
                }
            }
        }

      </span><span>/*</span><span>*******************************************************</span><span>*/</span>
                
<span>/*</span><span>*********************************************************</span><span>*/</span>

        <span>//</span><span>删除数据实现</span><span>
/*</span><span>******************************************************</span><span>*/</span>
        <span>private</span> <span>void</span> button3_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>/*</span><span>********************************************************</span><span>*/</span>
            <span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {

                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句</span>
                        cmd.CommandText = <span>"</span><span>select account_type from T_users where account_type='</span><span>"</span> + textBox1.Text + <span>"</span><span>';</span><span>"</span><span>;
                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span> (reader.Read())<span>//</span><span>存在该条记录</span>
<span>                            {
                                </span><span>//</span><span>执行删除操作</span>
                                <span>/*</span><span>*******************************************************</span><span>*/</span>
                                <span>//</span><span>与数据库建立连接</span>
                                <span>string</span> connectionString2 = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
                                {
                                    </span><span>using</span> (OleDbConnection conn2 = <span>new</span><span> OleDbConnection(connectionString2))
                                    {
                                        conn2.Open();</span><span>//</span><span>打开连接

                                        </span><span>//</span><span>创建SQL命令语句</span>
                                        <span>using</span> (OleDbCommand delete_cmd =<span> conn2.CreateCommand())
                                        {
                                            </span><span>//</span><span>SQL查询语句</span>
                                            delete_cmd.CommandText = <span>"</span><span>delete from T_users where account_type='</span><span>"</span> + textBox1.Text+ <span>"</span><span>';</span><span>"</span><span>;
                                            delete_cmd.ExecuteNonQuery();
                                        }
                                    }
                                }
                                </span><span>//</span><span>删除此combox选项</span>
                                <span>if</span> (comboBox1.Text ==<span> textBox1.Text)
                                {
                                    comboBox1.Items.Remove(comboBox1.Text);
                                }
                                </span><span>//</span><span>删除成功清空内容</span>
                                textBox1.Text = <span>""</span><span>;
                                textBox2.Text </span>= <span>""</span><span>;
                                textBox3.Text </span>= <span>""</span><span>;
                                textBox4.Text </span>= <span>""</span><span>;
                                textBox5.Text </span>= <span>""</span><span>;
                                MessageBox.Show(</span><span>"</span><span>删除成功!</span><span>"</span>, <span>"</span><span>删除成功提示</span><span>"</span><span>);
                            }
                            </span><span>else</span><span>
                            {
                                MessageBox.Show(</span><span>"</span><span>删除失败!</span><span>"</span>, <span>"</span><span>删除失败提示</span><span>"</span><span>);
                                </span><span>return</span><span>;
                            }
                        }
                    }
                }
            }
        }
</span><span>/*</span><span>************************************************************</span><span>*/</span>

        <span>//</span><span>清空</span><span>
/*</span><span>***********************************************************************</span><span>*/</span>
        <span>private</span> <span>void</span> button6_Click(<span>object</span><span> sender, EventArgs e)
        {
            textBox1.Text </span>= <span>""</span><span>;
            textBox2.Text </span>= <span>""</span><span>;
            textBox3.Text </span>= <span>""</span><span>;
            textBox4.Text </span>= <span>""</span><span>;
            textBox5.Text </span>= <span>""</span><span>;
        }
</span><span>/*</span><span>***********************************************************************</span><span>*/</span>
        
        <span>//</span><span>关键词搜索</span>
        <span>private</span> <span>void</span> button4_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>//</span><span>与数据库建立连接</span>
            <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句</span>
                        cmd.CommandText = <span>"</span><span>select * from T_users where account_type='</span><span>"</span> + textBox5.Text + <span>"</span><span>';</span><span>"</span><span>;

                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span> (reader.Read())<span>//</span><span><strong>账号</strong>类型存在存在</span>
<span>                            {
                                </span><span>string</span> db_type = reader.GetString(reader.GetOrdinal(<span>"</span><span>account_type</span><span>"</span><span>));
                                </span><span>string</span> db_website = reader.GetString(reader.GetOrdinal(<span>"</span><span>account_website</span><span>"</span><span>));
                                </span><span>string</span> db_username = reader.GetString(reader.GetOrdinal(<span>"</span><span>account_username</span><span>"</span><span>));
                                </span><span>string</span> db_password = reader.GetString(reader.GetOrdinal(<span>"</span><span>account_password</span><span>"</span><span>));
                                textBox1.Text </span>=<span>db_type;
                                textBox2.Text </span>= DecryptDES(db_website, <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                                textBox3.Text </span>= DecryptDES(db_username, <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                                textBox4.Text </span>= DecryptDES(db_password, <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                            }
                            </span><span>else</span> <span>//</span><span>reader返回false,搜索没有找到</span>
<span>                            {
                                MessageBox.Show(</span><span>"</span><span>对不起,没有找到!</span><span>"</span>, <span>"</span><span>搜索提示</span><span>"</span><span>);
                                </span><span>return</span><span>;
                            }
                        }
                    }
                }
            }

        }
        
        </span><span>//</span><span>下拉框搜索</span>
        <span>private</span> <span>void</span> comboBox1_SelectedIndexChanged(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
            {
                </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                {
                    conn.Open();</span><span>//</span><span>打开连接

                    </span><span>//</span><span>创建SQL命令语句</span>
                    <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                    {
                        </span><span>//</span><span>SQL查询语句</span>
                        cmd.CommandText = <span>"</span><span>select * from T_users where account_type='</span><span>"</span> + comboBox1.Text +<span>"</span><span>'</span><span>"</span><span>;
                        </span><span>//</span><span>读取查询结果内容</span>
                        <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                        {
                            </span><span>if</span><span> (reader.Read())
                            {
                                textBox1.Text </span>=reader.GetString(reader.GetOrdinal(<span>"</span><span>account_type</span><span>"</span><span>));
                                textBox2.Text </span>= DecryptDES((reader.GetString(reader.GetOrdinal(<span>"</span><span>account_website</span><span>"</span>))), <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                                textBox3.Text </span>= DecryptDES((reader.GetString(reader.GetOrdinal(<span>"</span><span>account_username</span><span>"</span>))), <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                                textBox4.Text </span>= DecryptDES((reader.GetString(reader.GetOrdinal(<span>"</span><span>account_password</span><span>"</span>))), <span>"</span><span>信息md5加密字符串</span><span>"</span><span>);
                            }
                            </span><span>else</span><span>
                            {
                                comboBox1.Items.Remove(comboBox1.Text);
                                </span><span>return</span><span>;
                            }
                        }
                    }
                }
            }
        }

        
        </span><span>/*</span><span> 在winform中,<strong>系统</strong>默认是不能够禁用窗体的关闭功能,
         * 但是,有时我们需要这种功能来屏蔽用户"随便"或不小心关闭造成的<strong>系统</strong>问题。 
         * 该方法操作起来十分简便,只要将以下一段代码添加到窗体累中就可以实现禁止窗体关闭按钮
         * 该方法让窗体的关闭按钮还是存在的,但是,鼠标操作关闭按钮是没有效果的。
         </span><span>*/</span>
    <span>/*</span><span>**************************************************************************</span><span>*/</span>
        <span>//</span><span>禁用鼠标右上角关闭按钮</span>
        <span>protected</span> <span>override</span> <span>void</span> WndProc(<span>ref</span><span>   Message m)
        {
            </span><span>const</span> <span>int</span> WM_SYSCOMMAND = <span>0x0112</span><span>;
            </span><span>const</span> <span>int</span> SC_CLOSE = <span>0xF060</span><span>;
            </span><span>if</span> (m.Msg == WM_SYSCOMMAND && (<span>int</span>)m.WParam ==<span> SC_CLOSE)
            {
                </span><span>return</span><span>;
            }
            </span><span>base</span>.WndProc(<span>ref</span><span> m);
        }
   </span><span>/*</span><span>*********************************************************************</span><span>*/</span>

        <span>//</span><span><strong>系统</strong>维护</span>
        <span>private</span> <span>void</span> button5_Click(<span>object</span><span> sender, EventArgs e)
        {
            Form3 fm3 </span>= <span>new</span><span> Form3();
            </span><span>this</span><span>.Hide();
            fm3.Show();
        }

        </span><span>//</span><span>退出<strong>系统</strong></span>
        <span>private</span> <span>void</span> button7_Click(<span>object</span><span> sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}</span>
Salin selepas log masuk

窗体三源码:

<span>using</span><span> System;
</span><span>using</span><span> System.Windows.Forms;
</span><span>using</span><span> System.Data.SqlClient;
</span><span>using</span><span> System.Data.OleDb;
</span><span>using</span><span> System.Security.Cryptography;
</span><span>using</span><span> System.Text;

</span><span>namespace</span><span> <strong>账号</strong><strong>密码</strong><strong>管理</strong><strong>系统</strong>1._0
{
    </span><span>public</span> <span>partial</span> <span>class</span><span> Form3 : Form
    {
        </span><span>public</span><span> Form3()
        {
            InitializeComponent();
        }

        </span><span>//</span><span>重置</span>
        <span>private</span> <span>void</span> button2_Click(<span>object</span><span> sender, EventArgs e)
        {
            textBox1.Text </span>= <span>""</span><span>;
            textBox2.Text </span>= <span>""</span><span>;
            textBox3.Text </span>= <span>""</span><span>;
            textBox4.Text </span>= <span>""</span><span>;
            textBox5.Text </span>= <span>""</span><span>;
        }

        </span><span>//</span><span>修改</span>
        <span>private</span> <span>void</span> button1_Click(<span>object</span><span> sender, EventArgs e)
        {
            </span><span>if</span> (textBox4.Text ==<span> textBox5.Text)
            {
                </span><span>//</span><span>与数据库建立连接</span>
                <span>string</span> connectionString = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
                {
                    </span><span>using</span> (OleDbConnection conn = <span>new</span><span> OleDbConnection(connectionString))
                    {
                        conn.Open();</span><span>//</span><span>打开连接

                        </span><span>//</span><span>创建SQL命令语句</span>
                        <span>using</span> (OleDbCommand cmd =<span> conn.CreateCommand())
                        {
                            </span><span>//</span><span>SQL查询语句</span>
                            cmd.CommandText = <span>"</span><span>select * from T_system where sys_username='</span><span>"</span> + GetMD5(textBox1.Text) + <span>"</span><span>';</span><span>"</span><span>;
                            </span><span>//</span><span>读取查询结果内容</span>
                            <span>using</span> (OleDbDataReader reader =<span> cmd.ExecuteReader())
                            {
                                </span><span>if</span> (reader.Read())<span>//</span><span>判断用户名是否存在</span>
<span>                                {
                                    </span><span>string</span> dbpassword = reader.GetString(reader.GetOrdinal(<span>"</span><span>sys_password</span><span>"</span><span>));
                                    </span><span>if</span> (dbpassword == GetMD5(textBox2.Text)) <span>//</span><span>原来<strong>密码</strong>输入正确</span>
<span>                                    {
                                        </span><span>//</span><span>更新数据库
                                        </span><span>//</span><span>添加信息插入到数据库内  </span>
                                        <span>/*</span><span>*********************************************************************</span><span>*/</span>
                                        <span>//</span><span>与数据库建立连接</span>
                                        <span>string</span> connectionString2 = <span>"</span><span>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Account_System.mdb;Jet OLEDB:Database Password=数据库<strong>密码</strong>设置处,此处已经修改</span><span>"</span><span>;
                                        {
                                            </span><span>using</span> (OleDbConnection conn2 = <span>new</span><span> OleDbConnection(connectionString2))
                                            {
                                                conn2.Open();</span><span>//</span><span>打开连接

                                                </span><span>//</span><span>创建SQL命令语句</span>
                                                <span>using</span> (OleDbCommand insert_cmd =<span> conn2.CreateCommand())
                                                {
                                                    </span><span>//</span><span>SQL查询语句</span>
                                                    insert_cmd.CommandText = <span>"</span><span>update T_system set sys_username='</span><span>"</span> + GetMD5(textBox3.Text) + <span>"</span><span>',sys_password='</span><span>"</span> + GetMD5(textBox4.Text) + <span>"</span><span>';</span><span>"</span><span>;
                                                    insert_cmd.ExecuteNonQuery();
                                                }
                                            }
                                        }
                                        MessageBox.Show(</span><span>"</span><span>恭喜您,修改成功!</span><span>"</span>, <span>"</span><span><strong>系统</strong>维护提示</span><span>"</span><span>);

                                    }
                                    </span><span>else</span><span>//</span><span>原<strong>密码</strong>输入错误 </span>
<span>                                    {
                                        MessageBox.Show(</span><span>"</span><span>对不起,原<strong>密码</strong>输入错误</span><span>"</span><span>);
                                        </span><span>return</span><span>;
                                    }
                                }
                                </span><span>else</span><span>
                                {
                                    MessageBox.Show(</span><span>"</span><span>原用户名输入错误!</span><span>"</span><span>);
                                    </span><span>return</span><span>;
                                }
                            }
                        }

                    }
                }
            }
            </span><span>else</span><span>
            {
                MessageBox.Show(</span><span>"</span><span>修改失败,新<strong>密码</strong>与确认<strong>密码</strong>不一致!</span><span>"</span>, <span>"</span><span>修改错误提示</span><span>"</span><span>);
                </span><span>return</span><span>;
            }

        }
        </span><span>//</span><span>MD5加密算法</span>
        <span>public</span> <span>static</span> <span>string</span> GetMD5(<span>string</span><span> str)
        {
            MD5 md5 </span>=<span> MD5.Create();
            </span><span>byte</span>[] buffer =<span> Encoding.Default.GetBytes(str);
            </span><span>byte</span>[] MD5buffer =<span> md5.ComputeHash(buffer);
            </span><span>string</span> strnew = <span>""</span><span>;
            </span><span>for</span> (<span>int</span> i = <span>0</span>; i )
            {
                strnew += MD5buffer[i].ToString(<span>"</span><span>x2</span><span>"</span><span>);
            }
            </span><span>return</span><span> strnew;
        }

        </span><span>private</span> <span>void</span> button3_Click(<span>object</span><span> sender, EventArgs e)
        {
            Form2 fm2 </span>= <span>new</span><span> Form2();
            </span><span>this</span><span>.Hide();
            fm2.Show();  
        }
    }
}</span>
Salin selepas log masuk
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan