Ejemplo n.º 1
0
        public ActionResult Doimatkhau(Customer kh, FormCollection collection)
        {
            var matkhaucu  = Mahoa.MD5Hash(collection["Matkhaucu"]);
            var matkhaumoi = Mahoa.MD5Hash(collection["Matkhaumoi"]);

            if (string.IsNullOrEmpty(matkhaucu))
            {
                ViewData["Loi1"] = "Phải nhập mật khẩu cũ";
            }
            else if (string.IsNullOrEmpty(matkhaumoi))
            {
                ViewData["Loi2"] = "Phải nhập mật khẩu mới";
            }
            Customer tk = (Customer)Session["Taikhoan"];

            if (tk.Password != matkhaucu)
            {
                ViewBag.Thongbao = "Mật khẩu cũ không đúng";
            }
            else
            {
                var khachhang = db.Customers.SingleOrDefault(x => x.ID == tk.ID);
                khachhang.Password = matkhaumoi;
                UpdateModel(khachhang);
                db.SubmitChanges();
                return(RedirectToAction("Index", "Home"));
            }
            return(this.Doimatkhau());
        }
Ejemplo n.º 2
0
        public ActionResult Dangnhap(FormCollection collection)
        {
            var tendn   = collection["Tendn"];
            var matkhau = Mahoa.MD5Hash(collection["Matkhau"]);

            if (string.IsNullOrEmpty(tendn))
            {
                ViewData["Loi1"] = "Phải nhập tài khoản";
            }
            else if (string.IsNullOrEmpty(matkhau))
            {
                ViewData["Loi2"] = "Phải nhập mật khẩu";
            }
            else
            {
                Customer kh      = db.Customers.SingleOrDefault(n => n.UserName == tendn && n.Password == matkhau);
                Customer kiemtra = db.Customers.SingleOrDefault(n => n.UserName == tendn);
                if (kiemtra == null)
                {
                    ViewBag.Thongbao = "Tên đăng nhập không tồn tại";
                }
                else
                {
                    if (kiemtra.Status == true)
                    {
                        if (kh == null)
                        {
                            ViewBag.Thongbao = "Mật khẩu không đúng";
                        }
                        else
                        {
                            ViewBag.Thongbao    = "Đăng nhập thành công!";
                            Session["Taikhoan"] = kh;
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ViewBag.Thongbao = "Tài khoản bị khóa";
                    }
                }
            }
            return(View());
        }
Ejemplo n.º 3
0
        private void Dangnhap()
        {
            int    iddonvi  = 1;
            Mahoa  _mahoa   = new Mahoa();
            string _matkhau = _mahoa.EncryptString(TxtPassword.Text, "lamgico");

            try
            {
                using (_theoDoiVanBanEntities = new TheoDoiVanBanEntities())
                {
                    var Id = _theoDoiVanBanEntities.login(iddonvi, TxtUsername.Text, _matkhau).FirstOrDefault();
                    if (Id != null)
                    {
                        this.DialogResult                  = DialogResult.OK;
                        DinhDanhAccount.Id_Account         = (int)Id.Id_Account;
                        DinhDanhAccount.FullName           = Id.FullName;
                        DinhDanhAccount.UserName           = Id.UserName;
                        DinhDanhAccount.Password           = Id.Password;
                        DinhDanhAccount.Avartar            = Id.Avartar;
                        DinhDanhAccount.Id_DonVi_Tbl_DonVi = Id.Id_DonVi_Tbl_DonVi;
                        DinhDanhAccount.Status             = (bool)Id.Status;
                        DinhDanhAccount.IdParent           = Id.IdParent;
                        DinhDanhAccount.NameParent         = Id.NameParent;
                        DinhDanhAccount.Level              = Id.Level;
                        DinhDanhAccount.TopLevelParent     = Id.TopLevelParent;

                        this.Close();
                    }
                    else
                    {
                        XtraMessageBox.Show("Sai tên đăng nhập hoặc mật khẩu\nHoặc tài khoản đã bị khóa");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
 public ActionResult Index(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         var dao       = new UserDao();
         var mahoaPass = new Mahoa();
         var result    = dao.Login(model.UserName, mahoaPass.MahoaMD5(model.UserPassword));
         if (result)
         {
             var user        = dao.DetailByUser(model.UserName);
             var userSession = new LoginModel();
             userSession.UserId     = user.Id;
             userSession.UserName   = model.UserName;
             userSession.RememberMe = model.RememberMe;
             SessionHelper.SetSessionUser(userSession);
             return(RedirectToAction("Index", "Default"));
         }
         else
         {
             ModelState.AddModelError("", "Đăng nhập không thành công!");
         }
     }
     return(View(model));
 }
Ejemplo n.º 5
0
 private void btnCapNhatPassWordMoi_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtNewPass.Text == "")
         {
             MessageBox.Show("Mật khẩu mới không được để trống", "Message"); return;
         }
         else
         {
             Function.ConnectSanXuat();
             string sqlQuery = string.Format(@"update AspNetUsers set AppPasswordHash = N'{0}' where UserName like N'{1}'",
                                             Mahoa.Encrypt(txtNewPass.Text.Trim()), txtUserName.Text.Trim());
             var kq = Function.GetDataTable(sqlQuery);
             XtraMessageBox.Show("Thao tác thành công[Success]", "Thông báo [Message]",
                                 MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch
     {
         XtraMessageBox.Show("Không thành công[UnSuccess]", "Thông báo [Message]",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 6
0
        public ActionResult Dangky(FormCollection collection, Customer kh)
        {
            var      hoten          = collection["HotenKH"];
            var      tendn          = collection["TenDN"];
            var      mk             = collection["Matkhau"];
            var      matkhau        = Mahoa.MD5Hash(mk);
            var      matkhaunhaplai = collection["Matkhaunhaplai"];
            var      diachiemail    = collection["Email"];
            var      diachi         = collection["Diachi"];
            var      dienthoai      = collection["Dienthoai"];
            var      ngaysinh       = String.Format("{0: MM/dd/yyyy}", collection["Ngaysinh"]);
            Customer kiemtra        = db.Customers.FirstOrDefault(n => n.UserName == tendn);

            if (String.IsNullOrEmpty(hoten))
            {
                ViewData["Loi1"] = "Họ tên không được để trống";
            }
            if (string.IsNullOrEmpty(tendn))
            {
                ViewData["Loi2"] = "Tên đăng nhập không được trống";
            }
            if (string.IsNullOrEmpty(matkhau))
            {
                ViewData["Loi3"] = "Phải nhập mật khẩu";
            }
            if (string.IsNullOrEmpty(matkhaunhaplai))
            {
                ViewData["Loi4"] = "Phải nhập mật khẩu";
            }
            if (string.IsNullOrEmpty(dienthoai))
            {
                ViewData["Loi5"] = "Chưa nhập điện thoại";
            }
            if (string.IsNullOrEmpty(diachiemail))
            {
                ViewData["Loi6"] = "Chưa nhập địa chỉ email";
            }
            if (string.IsNullOrEmpty(diachi))
            {
                ViewData["Loi7"] = "Chưa nhập địa chỉ khách hàng";
            }

            else
            {
                if (kiemtra != null)
                {
                    ViewData["Loi2"] = "Tên đăng nhập đã tồn tại";
                }
                else
                {
                    if (mk != matkhaunhaplai)
                    {
                        ViewData["Loi4"] = "Mật khẩu nhập lại không đúng";
                    }
                    else
                    {
                        kh.Name        = hoten;
                        kh.UserName    = tendn;
                        kh.Password    = matkhau;
                        kh.Email       = diachiemail;
                        kh.Address     = diachi;
                        kh.Phone       = dienthoai;
                        kh.CreatedDate = DateTime.Now;
                        kh.Status      = true;
                        db.Customers.InsertOnSubmit(kh);
                        db.SubmitChanges();
                        return(RedirectToAction("DangNhap"));
                    }
                }
            }
            return(this.Dangky());
        }