• 密码由6-12位数字或字母组成,密码哈希加密


            private void button1_Click(object sender, RoutedEventArgs e)
            {
                string pwdregex = "^[a-zA-Z0-9]{6,12}$";
                System.Text.RegularExpressions.Regex regPwd = new System.Text.RegularExpressions.Regex(pwdregex);
                if (!regPwd.IsMatch(PasswordBox1.Password.Trim()))
                {
                    label_warning.Content = "提示:密码由6-12位数字或字母组成!";
                }
                else if (PasswordBox1.Password.Equals(PasswordBox2.Password))
                {
                    MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                    byte[] str = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(PasswordBox1.Password));
                    string pwd = string.Empty;
                    for (int i = 0; i < str.Length; i++)
                    {
                        pwd += Convert.ToString(str[i], 16).PadLeft(2, '0');
                    }
                    try
                    {
                        using (StockManageDataContext smDataContext = new StockManageDataContext())
                        {
                            string usrname = (this.Parent as LoginWindow).User;
                            var s = smDataContext.Users.Single(c => c.UserName == usrname);
                            s.Password = pwd;
                            smDataContext.SubmitChanges();
                            MessageBox.Show("密码添加成功!");
                            this.NavigationService.Navigate(new Uri("LoginPage.xaml", UriKind.Relative));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        label_warning.Content = "提示:密码修改失败!";
                    }
    
                }
                else
                {
                    label_warning.Content = "提示:两次输入的密码不同!";
                }
            }
  • 相关阅读:
    python函数对象
    生成器表达式,列表推导式
    python转换excel成py文件
    Python处理excel表
    Go基础:接口相关
    JAVA03-输入和输出
    python6-while循环
    python5-字典
    自动化8-xpath
    网络学习day1-计算机网络基础
  • 原文地址:https://www.cnblogs.com/wenjieyatou/p/5351553.html
Copyright © 2020-2023  润新知