基本信息
源码名称:C# 通过TXT文本修改登录密码
源码大小:0.07M
文件格式:.rar
开发语言:C#
更新时间:2020-10-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 5 元 
   源码介绍

详细讲解了通过TXT文本记录密码,通过C#的文本的读写来修改密码

string oldpassword = tb_oldPwd.Text;
            string newpassword = tb_newPwd.Text;
            string repeatpassword = tb_conPwd.Text;
            if (oldpassword != common.password)
            {
                MessageBox.Show("旧密码错误");
                return;
            }
            if (newpassword != repeatpassword)
            {
                MessageBox.Show("密码不一致");
                return;
            }
            if (newpassword.Length < 7)
            {
                MessageBox.Show("密码长度必须大于6个字符");
                return;
            }
            if (newpassword == oldpassword)
            {
                MessageBox.Show("新旧密码不能一样");
                return;
            }
            else
            {
                #region
                #region //相对路径获取文本
                string parth = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));//.exe文件所在的路径去掉最后两截  E:\VS2015\program\AG2140二维码却换\TestOPC(\bin\Debug 即去掉这两截)
                #endregion
                parth = @"\config\system_config.txt";//操作文件路径的定义
                string[] strs = File.ReadAllLines(parth);
                int i = 0;

                foreach (string s in strs)
                {
                    if (i == 2)//这就是第3行的数据
                    {
                        string stra = strs[2];
                        string first = ":";
                        string second = ";";
                        //password出现的位置:
                        int IndexofA = stra.IndexOf(first);
                        int IndexofB = stra.IndexOf(second);
                        string newPwd = stra.Substring(IndexofA 1, IndexofB - IndexofA - 1);
                        newPwd = newPwd.Replace(newPwd, newpassword);
                        common.sInsertText = "password:" newPwd ";";
                    }
                    i ;
                }
                int iInsertLine = 3;

                string sText = "";
                System.IO.StreamReader sr = new System.IO.StreamReader(parth);
                int iLnTmp = 0; //记录文件行数
                while (iLnTmp < 2)//记录文件行数-1
                {
                    iLnTmp ;
                    if (iLnTmp == iInsertLine)
                    {
                        sText = common.sInsertText "\r\n";  //将值插入
                    }
                    string sTmp = sr.ReadLine();    //记录当前行
                    sText = sTmp "\r\n";
                }
                sr.Close();
                sText = common.sInsertText "\r\n";

                System.IO.StreamWriter sw = new System.IO.StreamWriter(parth, false);
                sw.Write(sText);
                sw.Flush();
                sw.Close();
                #endregion
                MessageBox.Show("密码修改成功");

                this.Close();
            }
        }