public ETLogin CheckDangKyHome(string pUsername, string pPassword, string pPassWord2, string pEmail, string pFullName, string pMobile) { Account mAccount = null; ETLogin mETLogin = new ETLogin(); try { //check xem 2 passs co trung nhau ko ? if (pPassword.Trim().Equals(pPassWord2.Trim())) { //lay danh sach tin moi dang nhat mAccount = (from p in entities.Account where p.UserName.Equals(pUsername) select p).FirstOrDefault(); if (!(mAccount != null)) { mAccount = new Account() { Email = pEmail, FullName = pFullName, Password = EncryptionMD5.ToMd5(pPassword), Phone = pMobile, UserName = pUsername, BirthDay = DateTime.Now }; entities.AddToAccount(mAccount); entities.SaveChanges(); mETLogin.Account = mAccount; mETLogin.code = 1; mETLogin.message = "Đăng ký thành công."; } else { mETLogin.code = 0; mETLogin.message = "Tài khoản đã tồn tại."; } } else { mETLogin.code = 0; mETLogin.message = "Password không trùng khớp."; } return(mETLogin); } catch (Exception ex) { Console.Write(ex); throw; } }
public string ChangePassword(int id, string newPassword) { using (var entities = new V308CMSEntities()) { var checkAdmin = (from account in entities.Admin where account.ID == id select account ).FirstOrDefault(); if (checkAdmin == null) { return("invalid"); } checkAdmin.Password = EncryptionMD5.ToMd5(newPassword); entities.SaveChanges(); return("ok"); } }
public Admin CheckAccount(string userName, string password) { using (var entities = new V308CMSEntities()) { var checkAdmin = (from admin in entities.Admin where admin.UserName.Equals(userName) || admin.Email.Equals(password) select admin).FirstOrDefault(); if (checkAdmin == null) { return(null); } if (checkAdmin.Password.Trim().Equals(EncryptionMD5.ToMd5(password.Trim()))) { return(checkAdmin); } return(null); } }
public string Insert(Admin data) { using (var entities = new V308CMSEntities()) { var checkAdmin = (from admin in entities.Admin where admin.UserName == data.UserName select admin ).FirstOrDefault(); if (checkAdmin == null) { data.Password = EncryptionMD5.ToMd5(data.Password.Trim()); entities.Admin.Add(data); entities.SaveChanges(); return("ok"); } return("exists"); } }
public ActionResult OnCreate(UserModels user) { if (ModelState.IsValid) { var newAccount = new Account { Email = user.Email, UserName = user.Username, Phone = user.Phone, FullName = user.FullName, Salt = StringHelper.GenerateString(6), Avata = user.Avatar != null ? user.Avatar.Upload() : user.AvatarUrl }; newAccount.Password = EncryptionMD5.ToMd5($"{user.Password}|{newAccount.Salt }"); newAccount.Address = user.Address; newAccount.Gender = user.Gender; newAccount.Date = user.CreateDate; DateTime birthDayValue; DateTime.TryParse(user.BirthDay, out birthDayValue); newAccount.BirthDay = birthDayValue; newAccount.Status = user.Status; var result = UserService.Insert(newAccount); if (result == Result.Exists) { ModelState.AddModelError("", $"Khách hàng {user.Email} đã được sử dụng để đăng ký."); return(View("Create", user)); } SetFlashMessage("Thêm khách hàng thành công."); if (user.SaveList) { return(RedirectToAction("Index")); } ModelState.Clear(); return(View("Create", user.ResetValue())); } return(View("Create", user)); }
public ETLogin CheckDangNhap(string pUsername, string pPassword) { Account user = null; ETLogin mETLogin = new ETLogin(); try { //lay danh sach tin moi dang nhat user = (from p in entities.Account where p.UserName.Equals(pUsername) || p.Email.Equals(pUsername) select p).FirstOrDefault(); if (user != null) { if (user.Password.Trim().Equals(EncryptionMD5.ToMd5(pPassword.Trim()))) { mETLogin.code = 1; mETLogin.message = "OK."; mETLogin.Account = user; mETLogin.role = int.Parse(user.Role.ToString()); } else { mETLogin.code = 2; mETLogin.message = "Mật khẩu không chính xác."; } } else { mETLogin.code = 0; mETLogin.message = "Không tìm thấy thông tin truy cập."; } return(mETLogin); } catch (Exception ex) { Console.Write(ex); throw; } }
public string Update(Admin data) { using (var entities = new V308CMSEntities()) { var adminUpdate = (from admin in entities.Admin where admin.ID == data.ID select admin ).FirstOrDefault(); if (adminUpdate != null) { adminUpdate.Password = EncryptionMD5.ToMd5(data.Password.Trim()); adminUpdate.Email = data.Email; adminUpdate.FullName = data.FullName; adminUpdate.Role = data.Role; adminUpdate.Date = data.Date; adminUpdate.Status = data.Status; adminUpdate.Type = data.Type; adminUpdate.Avatar = data.Avatar; entities.SaveChanges(); return("ok"); } return("not_exist"); } }
private string HashPassword(string password, string salt) { //return EncryptionMD5.ToMd5($"{password}|{salt}"); return(EncryptionMD5.ToMd5(string.Format("{password}|{salt}"))); }
public JsonResult CheckMarketRegister(string pUserName, string pPassWord, string pPassWord2, string pEmail, string pMobile, int pMarketType, string pSummary, string pImage, string pSumary, string InvisibleCaptchaValue, string Captcha = "", bool rbtAgree = false, string pFullName = "") { V308CMSEntities mEntities = new V308CMSEntities(); MarketRepository marketRepository = new MarketRepository(mEntities); ProductRepository productRepository = new ProductRepository(mEntities); AccountRepository accountRepository = new AccountRepository(mEntities); List <ProductType> mList; Market mMarket; Admin mAdmin; try { if (pPassWord.Trim().Equals(pPassWord2.Trim())) { if (pEmail.Length > 5 && pPassWord.Length > 5) { mAdmin = accountRepository.LayAdminTheoUserName(pEmail); if (!(mAdmin != null)) { mAdmin = new Admin() { Date = DateTime.Now, Role = 1, FullName = pFullName, Email = pEmail, UserName = pEmail, Password = EncryptionMD5.ToMd5(pPassWord.Trim()), //PSanPham = (true), //PFileUpload = (true), //PHeThong = (true), //PHinhAnh = (true), //PKhachHang = (true), //PTaiKhoan = (true), //PThungRac = (true), //PTinTuc = (true), Status = false }; mEntities.AddToAdmin(mAdmin); mEntities.SaveChanges(); //return Json(new { code = 1, message = "Lưu tài khoản thành công." }); } else { return(Json(new { code = 0, message = "Tài khoản đã tồn tại. Vui lòng tại tài khoản mới." })); } } else { return(Json(new { code = 0, message = "Mật khẩu và tài khoản và có độ dài tối thiểu 6 kí tự." })); } } else { return(Json(new { code = 0, message = "Mật khẩu xác nhận không trùng khớp." })); } //////////////////////////////////////////////////////////////////////////////////// /////////////////////////TẠO GIAN HÀNG /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// pImage = "http://cleanfoodvn.vn/Content/Images/logo.png"; mMarket = new Market() { Date = DateTime.Now, UserId = mAdmin.ID, BirthDay = DateTime.Now, UserName = Ultility.LocDau2(pUserName.Trim()), Avata = pImage, Email = pEmail, FullName = pFullName, Gender = true, Phone = pMobile, Role = pMarketType, Status = false, Sumary = pSumary }; mEntities.AddToMarket(mMarket); mEntities.SaveChanges(); //lay danh sách nhom san pham mList = productRepository.getProductTypeParent(); foreach (ProductType it in mList) { MarketProductType mMarketProductType = new MarketProductType() { Date = DateTime.Now, Name = it.Name, Detail = it.Name, Parent = it.ID, Status = true, Visible = true, Number = 1, MarketId = mMarket.ID, MarketName = mMarket.UserName, ImageBanner = it.ImageBanner }; mEntities.AddToMarketProductType(mMarketProductType); } mEntities.SaveChanges(); return(Json(new { code = 1, message = "Lưu cửa hàng thành công." })); } catch (Exception ex) { return(Json(new { code = 0, message = "Có lỗi xảy ra. Vui lòng thử lại." })); } finally { mEntities.Dispose(); marketRepository.Dispose(); } }
private string HashPassword(string password, string salt) { return(EncryptionMD5.ToMd5(string.Format("{0}|{1}", password, salt))); }
private string getToken(string email, bool forForgotPassword = false) { return(forForgotPassword? EncryptionMD5.ToMd5(string.Format("{0}|{1}|forgot-die", email, DateTime.Now.Ticks)):EncryptionMD5.ToMd5(string.Format("{0}|{1}", email, DateTime.Now.Ticks))); }