WPF修改账号密码

时间:2024-03-27 21:36:45

修改账号密码页面:

WPF修改账号密码

下面是代码实现:

 

        /// <summary>

        /// 修改密码保存

        /// </summary>

        private void Submit()

        {

           

            MD5 d = new MD5();

            string jM = d.md5(txtNewPasswordQR.Password, 32);

            string jieM = d.md5(txtOldPassword.Password, 32);

            if (!String.IsNullOrEmpty(txtYHM.Text) && !String.IsNullOrEmpty(txtOldPassword.Password) && !String.IsNullOrEmpty(txtNewPassword.Password) && !String.IsNullOrEmpty(txtNewPasswordQR.Password))

            {

                if (txtNewPassword.Password.Length >= 6)

                {

                    if (Regex.IsMatch(txtNewPassword.Password, @"^[A-Za-z0-9]{6,16}$"))

                    {

                        var olds = (from tbUser in myModels.PW_User where tbUser.UserNuber == strUserNumber select tbUser).Single();

                        if (olds.Password == jieM)

                        {

                            if (txtNewPassword.Password.Trim() == txtNewPasswordQR.Password.Trim())

                            {

 

                                olds.UserName = txtYHM.Text.Trim();

                                olds.Password = jM;

                                myModels.Entry(olds).State = System.Data.Entity.EntityState.Modified;

                                myModels.SaveChanges();

                                MessageBox.Show("密码修改成功!", "????", MessageBoxButton.OK, MessageBoxImage.None);

                                cP("密码修改成功") ;

                                WD_LoginWindow lW = new WD_LoginWindow();

                                this.Close();                               

                                lW.Show();

                                //add(txtZH.Text.Trim());

                            }

                            else

                            {

                                MessageBox.Show("密码填写不对应!", "????", MessageBoxButton.OK, MessageBoxImage.Stop);

                            }

 

                        }

                        else

                        {

                            MessageBox.Show("旧密码不正确,请重新输入!", "", MessageBoxButton.OK, MessageBoxImage.Question);

                        }

                    }

                    else

                    {

                        MessageBox.Show("请填写正确的密码,由6到16个数字和字母组成!!!");

                    }

 

                }

                else

                {

                    MessageBox.Show("密码长度不能少于六位");

                }

            }

            else

            {

                MessageBox.Show("请填写完整!", "Error", MessageBoxButton.OK, MessageBoxImage.Question);

            }

 

        }