コード例 #1
0
        private void btnDoiMK_Click(object sender, EventArgs e)
        {
            string passMD5_a = txt_MatKhau.Text;

            passMD5_a = getMD5(txt_MatKhau.Text);// Chuỗi đã mã hóa sang MD5

            string passMD5_b = txt_newPass.Text;

            passMD5_b = getMD5(txt_newPass.Text);

            //string passMD5_b2 = txt_MatKhau.Text;
            //passMD5_b2 = getMD5(txt_MatKhau.Text);


            string pass    = txt_newPass.Text;
            string newPass = txt_rePass.Text;

            if (txt_TaiKhoan.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập tài khoản!",
                                "Nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_TaiKhoan.Focus();
            }
            else
            if (txt_MatKhau.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập mật khẩu!",
                                "Nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_MatKhau.Focus();
            }
            else
            {
                string sqlAdmin = "select * from dbo.DangNhap where TaiKhoan = '" +
                                  txt_TaiKhoan.Text + "' and MatKhau='" +
                                  passMD5_a + " '";
                DataTable ba = CSDL.bang(sqlAdmin);
                int       i  = ba.Rows.Count;

                //Bảng Người Dùng

                if (i == 0)
                {
                    MessageBox.Show("Bạn nhập sai tài khoản hoặc mật khẩu !", "Đổi Mật Khẩu",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txt_TaiKhoan.Focus();
                }
                else
                {
                    if (i > 0)
                    {
                        try
                        {
                            if (pass == "" || newPass == "")
                            {
                                MessageBox.Show("Mật khẩu mới không được để trống !", "Nhập Liệu",
                                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                                txt_newPass.Focus();
                            }
                            else
                            {
                                if (pass == newPass)
                                {
                                    string sqlUpdate = "update dbo.DangNhap set MatKhau ='" +
                                                       passMD5_b + "' where TaiKhoan = '" +
                                                       txt_TaiKhoan.Text + "' ";
                                    CSDL.ThemSuaXoa(sqlUpdate);
                                    MessageBox.Show("Bạn đã đổi mật khẩu thành công!", "Đổi Mật Khẩu"
                                                    , MessageBoxButtons.OK, MessageBoxIcon.Information);

                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("Mật khẩu mới không khớp, vui lòng kiểm tra lại!", "Nhập Liệu"
                                                    , MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Thao tác không thể thực hiện được, vui lòng kiểm tra lại!", "Đổi Mật Khẩu"
                                            , MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void button_DangNhap_Click_1(object sender, EventArgs e)
        {
            try
            {
                string passMD5 = getMD5(textBox_Pass.Text);
                string tentk   = textBox_User.Text;
                string matkhau = textBox_Pass.Text;
                if (tentk == "")
                {
                    MessageBox.Show("Bạn chưa nhập tên tài khoản",
                                    "Đăng nhập", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (matkhau == "")
                    {
                        MessageBox.Show("Bạn chưa nhập mật khẩu",
                                        "Đăng Nhập", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        string dangNhap = "SELECT * FROM DangNhap WHERE TaiKhoan = '" +
                                          textBox_User.Text + "' and MatKhau='" +
                                          passMD5 + " '";
                        DataTable dt = CSDL.bang(dangNhap);
                        int       i  = dt.Rows.Count;


                        if (sai > 0)
                        {
                            if (i > 0)
                            {
                                DataTable datadn = CSDL.bang(dangNhap);
                                tk = int.Parse(datadn.Rows[0][2].ToString());//Lấy thông tin cấp độ tài khoản
                                if (tk == 1)
                                {
                                    MessageBox.Show("Quản trị viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập",
                                                    "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    //this.Close();
                                }
                                else if (tk == 2)
                                {
                                    MessageBox.Show("Giáo viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập",
                                                    "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else if (tk == 3)
                                {
                                    MessageBox.Show("Sinh viên " + "\"" + textBox_User.Text + "\"" + " đã đăng nhập",
                                                    "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    tk = 0;
                                }

                                using (Form1 gd = new Form1())
                                {
                                    if (tk == 1 || tk == 2)
                                    {
                                        gd.getUsername = textBox_User.Text;
                                    }
                                    else
                                    {
                                        gd.getUsername2 = textBox_User.Text;
                                    }
                                    gd.ShowDialog();
                                    this.Close();
                                }
                            }
                            else
                            {
                                tk  = 0;
                                sai = sai - 1;
                                MessageBox.Show("Sai tên tài khoản hoặc mật khẩu! Bạn còn " + sai + " lần đăng nhập",
                                                "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.textBox_User.Clear();
                                this.textBox_Pass.Clear();
                                this.textBox_User.Focus();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Bạn đã hết lượt truy cập đăng nhập. Mời đăng nhập lại!",
                                            "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Close();
                            Form_DangNhap gd1 = new Form_DangNhap();
                            gd1.Show();
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Lỗi kết nối với máy chủ, vui lòng thử lại",
                                "Lỗi kết nối", MessageBoxButtons.OK, MessageBoxIcon.Error);
            };
        }