CTI的修改密码模块和退出模块

本文详细介绍了如何在用户界面中实现密码修改功能,并通过调用数据库操作来更新用户的密码。包括验证旧密码、确认新密码一致性和安全性,以及执行数据库更新的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

From1 准备传值代码:

Password pa = new Password();

            pa.MdiParent = this;//声明 PassWord的父窗体是本窗体( Form1)
            pa.NaVa = NaVa;
            pa.PaVa = PaVa;

            pa.Show();


PassWord:

public string NaVa = string.Empty;
        public string PaVa = string.Empty;


点击修改密码:

private void button1_Click(object sender, EventArgs e)
        {
            if (this.txt_old.Text==PaVa)
            {
                if (this.txt_new.Text==this.txt_new2.Text)
                {

                    string str = ConfigurationManager.ConnectionStrings["sqlcnn"].ConnectionString;
                    SqlConnection cnn = new SqlConnection(str);
                    SqlCommand cmm = new SqlCommand();
                    cmm.Connection = cnn;
                    cmm.CommandText = "update T_Login set  Password=@password where UserName=@username";
                    cmm.Parameters.AddWithValue("@password", txt_new.Text);
                    cmm.Parameters.AddWithValue("@username", NaVa);
                    cnn.Open();
                    cmm.ExecuteNonQuery();
                    cnn.Close();
                    MessageBox.Show("密码修改成功!");
                    
                    this.Close();
                }
                else
                {
                    txt_old.Text = "";
                    txt_new.Text = "";
                    txt_new2.Text = "";
                    MessageBox.Show("两次输入的密码不一致,请重新输入!");
                }
                return;
            }
        
            else
            {
                txt_old.Text = "";
                txt_new.Text = "";
                txt_new2.Text = "";
                MessageBox.Show("你输入的密码错误,请重新输入!");

            }

//给子窗体定位,离顶部120px;

 private void Password_Load(object sender, EventArgs e)
        {
            this.Top = 120;
        }
      

//退出。结束整个进程

 Application.Exit();



            



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值