Ejemplo n.º 1
0
 private void btnDoiMatKhau_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtPassword2.Text == txtPassword3.Text)
         {
             if (Ham.EncodePassword(txtPassword1.Text) == passwordCu)
             {
                 cn.ExecuteNonQuery("UPDATE HTUSER set matkhau = N'" + Ham.EncodePassword(txtPassword2.Text) + "' where id = " + id);
                 MessageBox.Show("Thay đổi thông tin thành công", "Thông báo");
                 passwordCu        = Ham.EncodePassword(txtPassword2.Text);
                 txtPassword2.Text = "";
                 txtPassword1.Text = "";
                 txtPassword3.Text = "";
             }
             else
             {
                 MessageBox.Show("Mật khẩu cũ không chính xác", "Thông báo");
             }
         }
         else
         {
             MessageBox.Show("Mật khẩu mới không trùng nhau", "Thông báo");
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        private void TaiTaiKhoan()
        {
            try
            {
                string ten, ngaysinh, sdt, quequan, username, password, email;

                bool active = true;
                bool gioitinh;
                ten      = txtHoTen.Text;
                ngaysinh = dateNgaySinh.Value.ToString();
                gioitinh = cbGioiTinh.SelectedItem.ToString() == "Nam" ? true : false;
                sdt      = txtSDT.Text;
                quequan  = txtDiaChi.Text;
                username = txtTaiKhoan.Text;
                password = Ham.EncodePassword(txtMatKhau.Text);
                email    = txtEmail.Text;
                if (!String.IsNullOrEmpty(txtHoTen.Text) && !String.IsNullOrEmpty(txtMatKhau.Text) && !String.IsNullOrEmpty(txtTaiKhoan.Text))
                {
                    if (txtMatKhau2.Text == txtMatKhau.Text)
                    {
                        if (!CheckUsername(username))
                        {
                            MessageBox.Show("Tài khoản đã tồn tại trong hệ thống!", "Thông báo!");
                        }
                        else
                        {
                            string sql = "Insert into HTUser (ten,ngaysinh,sdt,gioitinh,diachi,taikhoan,matkhau,active,roleId,email) values(N'" + ten +
                                         "','" + ngaysinh + "','" + sdt + "','" + gioitinh + "',N'" + quequan + "','" + username + "','" + password + "','" + active + "'," + quyen + ",'" + email + "')";
                            conn.ExecuteNonQuery(sql);
                            MessageBox.Show("Tạo tài khoản thành công!", "Thông báo");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Mật khẩu không khớp!", "Thông báo!");
                    }
                }
                else
                {
                    MessageBox.Show("Kiểm tra lại thông tin!", "Thông báo!");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Kiểm tra lại thông tin!", "Thông báo!");
            }
        }
Ejemplo n.º 3
0
        private void DoiMatKhau()
        {
            string email, username, pass1, pass2;

            email    = txtEmail.Text;
            username = txtUsername.Text;
            pass1    = txtPass1.Text;
            pass2    = txtPass2.Text;
            if (pass1.Length < 6 || pass2.Length < 6 || pass1 != pass2)
            {
                lbThongBao.Text = "Mật khẩu không hợp lệ!";
            }
            else
            {
                string password = Ham.EncodePassword(pass1);
                cn.ExecuteNonQuery("UPDATE HTUser set matkhau = '" + password + "' where email = '" + email + "' and taikhoan = '" + username + "'");
                MessageBox.Show("Đổi mật khẩu thành công!", "Thông báo");
                DangNhap d = new DangNhap();
                d.Show();
                this.Close();
            }
        }
Ejemplo n.º 4
0
        private void LoginAdmin()
        {
            var read = conn.getDataTable("SELECT * FROM HTUser WHERE taikhoan = N'" + txtTaiKhoan.Text +
                                         "' and matkhau = '" + Ham.EncodePassword(txtMatKhau.Text) + "' and active = 'true'");

            if (read.Rows.Count > 0)
            {
                LuuThongTin.id       = int.Parse(read.Rows[0][0].ToString());
                LuuThongTin.ten      = read.Rows[0][1].ToString();
                LuuThongTin.ngaysinh = read.Rows[0][2].ToString();
                LuuThongTin.sdt      = read.Rows[0][3].ToString();
                LuuThongTin.gioitinh = read.Rows[0][4].ToString() == "True" ? true : false;
                LuuThongTin.diachi   = read.Rows[0][5].ToString();
                LuuThongTin.taikhoan = read.Rows[0][6].ToString();
                LuuThongTin.roleId   = Int32.Parse(read.Rows[0][9].ToString());
                LuuThongTin.email    = read.Rows[0][10].ToString();

                var role = conn.getDataTable("SELECT * FROM HTRole WHERE id = " + LuuThongTin.roleId);
                LuuThongTin.role = role.Rows[0][1].ToString();
                Console.WriteLine(LuuThongTin.role);
                this.Hide();
                if (LuuThongTin.role == "Khachhang")
                {
                    // KHACH HANG
                    TrangChuKhachHang trangChu = new TrangChuKhachHang();
                    trangChu.ShowDialog();
                }
                else
                {
                    // NHAN VIEN
                    TrangChuNhanVien trangChu = new TrangChuNhanVien();
                    trangChu.ShowDialog();
                }
            }
            else
            {
                lbLoginFailed.Text = "Tài khoản hoặc mật khẩu không đúng !";
            }
        }