Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            userID = this.maskedTextBox1.Text;
            cardID = this.maskedTextBox2.Text;
            pwd    = this.maskedTextBox9.Text;
            name   = this.textBox1.Text;
            phone  = this.textBox2.Text;
            if (userID == "")
            {
                MessageBox.Show("请填写证件号码");
                return;
            }
            if (cardID == "")
            {
                MessageBox.Show("请填写账户号码");
                return;
            }

            if (this.maskedTextBox10.Text.Equals(pwd) != true)
            {
                this.label14.Text              = "密码与确认密码不一致";
                this.label14.ForeColor         = Color.Red;
                this.maskedTextBox10.BackColor = Color.LightCoral;
                this.maskedTextBox9.BackColor  = Color.LightCoral;
                return;
            }
            if (name == "")
            {
                MessageBox.Show("请填写姓名");
                return;
            }
            if (this.radioButton1.Checked)
            {
                gender = this.radioButton1.Text;
            }
            else if (this.radioButton2.Checked)
            {
                gender = this.radioButton2.Text;
            }
            else
            {
                gender = "";
            }
            if (gender == "")
            {
                MessageBox.Show("请选择性别");
                return;
            }
            int check = PasswordSafe.PwdSafety(pwd, userID);

            if (check == -1)
            {
                MessageBox.Show("密码请输入6位数字", "开户", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (check == -2)
            {
                MessageBox.Show("请输入正确的身份证件号", "开户", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (check == 0)
            {
                MessageBox.Show("设置密码过简单!\n容易被破解!\n请勿使用出生日期、123456等简单密码!", "开户", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            pwd_md5 = pwd.Md5();
            string inst_Card      = string.Format("INSERT INTO Card(cardID, userID, Pwd) VALUES('{0}','{1}','{2}');", cardID, userID, pwd_md5);
            string inst_Account   = string.Format("INSERT INTO Account(userID, Name, Phone, Gender) VALUES('{0}','{1}','{2}','{3}');", userID, name, phone, gender);
            string SELECT_Account = string.Format("SELECT * FROM Account WHERE userID='{0}';", userID);

            using (SqlConnection conn = new SqlConnection(constr))
            {
                conn.Open();
                SqlTransaction sqlTran;
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    sqlTran         = conn.BeginTransaction();
                    cmd.Connection  = conn;
                    cmd.Transaction = sqlTran;
                    try
                    {
                        cmd.CommandText = SELECT_Account;
                        if ((int)cmd.ExecuteNonQuery() == -1)
                        {
                            cmd.CommandText = inst_Account;
                            cmd.ExecuteNonQuery();
                        }

                        cmd.CommandText = inst_Card;
                        cmd.ExecuteNonQuery();
                        sqlTran.Commit();
                        MessageBox.Show("开户激活成功!\n请注意密码的保密,安全用卡!", "开户", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception err)
                    {
                        sqlTran.Rollback();
                        string err_str = string.Format("开户激活失败!\n该账户已激活,请直接使用!\n\n错误:{0}", err.Message);
                        MessageBox.Show(err_str, "开户", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        Console.Error.WriteLine("错误:" + err.Message);
                    }
                }
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string ID = this.maskedTextBox7.Text;

            if (ID == "")
            {
                MessageBox.Show("请填写证件号码");
                return;
            }
            string CardID = this.maskedTextBox8.Text;

            if (CardID == "")
            {
                MessageBox.Show("请填写账户号码");
                return;
            }

            if (this.maskedTextBox9.Text.Equals(this.maskedTextBox10.Text) != true)
            {
                this.label14.Text              = "密码与确认密码不一致";
                this.label14.ForeColor         = Color.Red;
                this.maskedTextBox10.BackColor = Color.LightCoral;
                this.maskedTextBox9.BackColor  = Color.LightCoral;
                return;
            }

            string pwd   = this.maskedTextBox9.Text;
            int    check = PasswordSafe.PwdSafety(pwd, ID);

            if (check == -1)
            {
                MessageBox.Show("密码请输入6位数字", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (check == -2)
            {
                MessageBox.Show("请输入正确的身份证件号", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (check == 0)
            {
                MessageBox.Show("设置密码过简单!\n容易被破解!\n请勿使用出生日期、123456等简单密码!", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string pwd_md5 = pwd.Md5();
            string query   = string.Format("Select Card.Pwd FROM Card WHERE cardID='{0}' AND userID='{1}';", CardID, ID);

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                SqlCommand cmd_query = new SqlCommand();
                cmd_query.CommandText = query;
                cmd_query.Connection  = conn;
                try
                {
                    conn.Open();
                    string res = cmd_query.ExecuteScalar().ToString();
                    if (res == "")
                    {
                        MessageBox.Show("提供的证件名下没有该账户\n请重新输入正确的证件号码和账户号码", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (pwd_md5.Equals(res))
                    {
                        MessageBox.Show("新密码不能与旧密码一致", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        string     inst     = string.Format("UPDATE Card SET Pwd='{0}' WHERE cardID='{1}' AND userID='{2}';", pwd_md5, CardID, ID);
                        SqlCommand cmd_inst = new SqlCommand();
                        cmd_inst.CommandText = inst;
                        cmd_inst.Connection  = conn;
                        if ((int)cmd_inst.ExecuteNonQuery() != 0)
                        {
                            MessageBox.Show("密码更改成功!\n请牢记新密码,注意保密!", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Client.chance = 5;
                        }
                        else
                        {
                            MessageBox.Show("密码更改失败!", "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                }
                catch (Exception err)
                {
                    string err_str = string.Format("密码更改失败!\n\n错误:{0}", err.Message);
                    MessageBox.Show(err_str, "更改密码", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }