public string EncodeCredentials(string userId, string password) { string encoded = string.Empty; encoded = RijndaelCrypt.Encrypt(password, AppIdentifier()); return(encoded); }
public async Task <IActionResult> Forgot(Forgot model) { if (ModelState.IsValid) { var customer = this._context.Customers.Include(i => i.CustomerClass).Include(i => i.User).Where(c => c.User.UserName == model.Email).FirstOrDefault(); if (customer != null) { model.Customer = customer; var rg = new RijndaelCrypt(); model.Url = Url.Action("ResetPwd", new { u = rg.Encrypt(customer.User.UserName) }); var htmlToConvert = await RenderViewAsync("MailForgotPwd", model, true); var msg = EmailUtil.sendNotificationEmail(_smtp, customer.Email, "เปลี่ยนรหัสผ่าน", htmlToConvert.ToString()); ViewData["Message"] = "ระบบกำลังส่่งการกำหนดรหัสผ่านใหม่ไปยังอีเมลของท่าน"; return(View(model)); } ViewData["ErrorMessage"] = "ไม่พบอีเมลในระบบ"; } else { ViewData["ErrorMessage"] = "โปรดระบุอีเมล"; } return(View(model)); }
/// <summary> /// 加密数据 /// </summary> /// <param name="encryptString"></param> /// <returns></returns> public static string EncryptData(string encryptString) { if (string.IsNullOrEmpty(encryptString)) { throw new ArgumentNullException("EncryptDBConnString()方法,参数encryptString值为空"); } string key = GetEncryptKey(); if (string.IsNullOrEmpty(key)) { throw new Exception("配置中未读取到客户密钥串"); } return(RijndaelCrypt.Encrypt(encryptString, key)); }
private void btnEncrypt_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(rtxtString.Text)) { MessageBox.Show("字符串不能为空"); return; } if (string.IsNullOrEmpty(txtSecretKey.Text)) { MessageBox.Show("密钥不能为空"); return; } string encryptString = RijndaelCrypt.Encrypt(rtxtString.Text.Trim(), txtSecretKey.Text.Trim()); rtxtEncryString.Text = encryptString; }
private TaskEntity InsertTask() { TaskEntity taskEntity = new TaskEntity(); taskEntity.TaskID = Guid.NewGuid().ToString("N"); taskEntity.DataType = DataTypes.Sale; taskEntity.Cron = "0 3 * * * ? *"; taskEntity.DataHandler = "Transfer8Pro.DAO.DataHandlers.SqlServer_DataHandler"; string connStr = @"server=192.168.0.14;database=Smart_NewBookDB;uid=sa;pwd=sa.;min pool size=10;max pool size=300;Connection Timeout=10;"; string encryptKey = Common.GetEncryptKey(); taskEntity.DBConnectString_Hashed = RijndaelCrypt.Encrypt(connStr, encryptKey); taskEntity.SQL = "SELECT * FROM dbo.T8_BookInfo WHERE SalesDateTime>=@StartTime AND SalesDateTime<=@EndTime"; taskEntity.TaskName = "天销售数据" + DateTime.Now.ToLongTimeString(); //taskEntity.Enabled = true; taskEntity.IsDelete = false; taskEntity.TaskStatus = TaskStatus.RUN; taskEntity.CreateTime = DateTime.Now; return(taskEntity); }
public static void SecureFileCrypt(this ICakeContext context, FilePath file, FilePath encryptedFile, string secret) { RijndaelCrypt.Encrypt(file.FullPath, encryptedFile.FullPath, secret); }
public async Task <IActionResult> Register(CustomerDTO model, bool repair = false) { if (ModelState.IsValid) { if (!repair) { if (string.IsNullOrEmpty(model.username)) { model.username = model.email; } if (!model.isDhiMember) { model.citizenId = null; } if (this.isExistIDCard(model)) { var rg = new RijndaelCrypt(); model.ShowIdcardDupPopup = true; var ducus = this._context.Customers.Include(i => i.User).Where(c => c.IDCard == model.citizenId & (model.ID > 0 ? c.ID != model.ID : true)); model.dupEmail = new List <string>(); model.dupFBID = new List <string>(); foreach (var cus in ducus) { if (string.IsNullOrEmpty(cus.FacebookID)) { model.dupEmail.Add(cus.User.UserName); } else { model.dupFBID.Add(cus.User.UserName); } model.dupIdcard = model.citizenId; } ModelState.AddModelError("citizenId", "รหัสบัตรประชาชนซ้ำในระบบ"); } if (this.isExistEmail(model)) { ModelState.AddModelError("email", "อีเมลซ้ำในระบบ"); } if (this.isExistUserName(model)) { ModelState.AddModelError("email", "รหัสผู้ใช้งานซ้ำในระบบ"); } //if (this.isExistMobileNo(model)) // ModelState.AddModelError("moblieNo", "เบอร์โทรศัพท์ซ้ำในระบบ"); //if (this.isExistName(model)) //{ // ModelState.AddModelError("firstName", "ชื่อนามสกุลซ้ำในระบบ"); // ModelState.AddModelError("lastName", "ชื่อนามสกุลซ้ำในระบบ"); //} if (!string.IsNullOrEmpty(model.friendCode) && !this.isExistFriendCode(model)) { ModelState.AddModelError("friendCode", "ไม่พบข้อมูล friend Code"); } } if (ModelState.IsValid) { if (model.valid) { model.password = DataEncryptor.Decrypt(model.pEncyprt); var customer = new Customer(); customer.Create_On = DateUtil.Now(); customer.ChannelUpdate = CustomerChanal.TIP; customer = CustomerBinding.Binding(customer, model); GetCustomerClass(customer); customer.Create_On = DateUtil.Now(); customer.Create_By = customer.User.UserName; customer.Update_On = DateUtil.Now(); customer.Update_By = customer.User.UserName; customer.Success = false; var regs = this.GetPointCondition(customer, TransacionTypeID.Register); foreach (var item in regs) { if (item.Point.Value > 0) { var point = this.GetCustomerPoint(item, customer, item.Point.Value, (int)TransacionTypeID.Register, CustomerChanal.TIP, "tipsociety-register"); customer.CustomerPoints.Add(point); } } var friendpoint = 0; Customer friend = null; if (!string.IsNullOrEmpty(customer.FriendCode)) { var invites = this.GetPointCondition(customer, TransacionTypeID.InviteFriend); foreach (var item in invites) { var p = this.GetPoint(item, customer); if (p > 0) { var point = this.GetCustomerPoint(item, customer, p, (int)TransacionTypeID.InviteFriend, CustomerChanal.TIP, "tipsociety-register"); friend = this._context.Customers.Where(w => w.RefCode == customer.FriendCode).FirstOrDefault(); if (friend != null) { friendpoint = p; point.CustomerID = friend.ID; this._context.CustomerPoints.Add(point); } } } } this._context.Customers.Add(customer); this._context.SaveChanges(); this._context.Entry(customer).GetDatabaseValues(); customer.RefCode = CustomerBinding.GetRefCode(customer); this._context.Users.Attach(customer.User); this._context.Entry(customer.User).Property(u => u.Email).IsModified = true; this._context.Entry(customer.User).Property(u => u.PhoneNumber).IsModified = true; this._context.Update(customer); this._context.SaveChanges(); AddConsent(model); if (_conf.SendEmail == true && friend != null && friendpoint > 0) { await MailInviteFriend(friend.Email, friend, customer, friendpoint); } try { if (!repair) { using (var client = new HttpClient()) { client.BaseAddress = new Uri(_mobile.Url + "/rewardpoint/customerprofile/register"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var rg = new RijndaelCrypt(); model.username = rg.Encrypt(model.username); model.password = rg.Encrypt(model.password); model.status = customer.Status.toStatusNameEn(); StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content); if (response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.OK) { customer.Success = true; this._context.SaveChanges(); } else { _logger.LogWarning(JsonConvert.SerializeObject(model)); _logger.LogWarning(await response.Content.ReadAsStringAsync()); } } } } catch { } if (_conf.SendEmail == true) { await MailActivateAcc(customer.Email, customer.ID); } //if (_conf.SendSMS == true) // SendSMS(customer.ID); return(await Login(new Login() { UserName = model.email, Password = model.password }, true)); } else { model.pEncyprt = DataEncryptor.Encrypt(model.password); } model.valid = true; } } return(View(model)); }
public async Task <IActionResult> Terminate(string code) { var acccode = this._context.AccountCodes.Where(w => w.Code == code && w.Status == StatusType.Active).FirstOrDefault(); if (acccode != null) { var customer = _context.Customers.Where(w => w.ID == acccode.CustomerID).FirstOrDefault(); if (customer != null) { var redeems = this._context.Redeems.Where(w => w.CustomerID == customer.ID); var mobile = this._context.MobilePoints.Where(w => w.CustomerID == customer.ID); var classchages = this._context.CustomerClassChanges.Where(w => w.CustomerID == customer.ID); var adjusts = this._context.PointAdjusts.Where(w => w.CustomerID == customer.ID); var points = this._context.CustomerPoints.Where(w => w.CustomerID == customer.ID); var tempcus = JsonConvert.SerializeObject(customer, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var tcus = new TerminateCustomer(); tcus = JsonConvert.DeserializeObject <TerminateCustomer>(tempcus); tcus.ID = 0; tcus.CustomerID = customer.ID; this._context.TerminateCustomers.Add(tcus); foreach (var item in redeems) { var temp = JsonConvert.SerializeObject(item, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var t = new TerminateRedeem(); t = JsonConvert.DeserializeObject <TerminateRedeem>(temp); t.ID = 0; this._context.TerminateRedeems.Add(t); } foreach (var item in points) { var temp = JsonConvert.SerializeObject(item, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var t = new TerminateCustomerPoint(); t = JsonConvert.DeserializeObject <TerminateCustomerPoint>(temp); t.ID = 0; this._context.TerminateCustomerPoints.Add(t); } foreach (var item in mobile) { var temp = JsonConvert.SerializeObject(item, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var t = new TerminateMobilePoint(); t = JsonConvert.DeserializeObject <TerminateMobilePoint>(temp); t.ID = 0; this._context.TerminateMobilePoints.Add(t); } foreach (var item in classchages) { var temp = JsonConvert.SerializeObject(item, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var t = new TerminateCustomerClassChange(); t = JsonConvert.DeserializeObject <TerminateCustomerClassChange>(temp); t.ID = 0; this._context.TerminateCustomerClassChanges.Add(t); } foreach (var item in adjusts) { var temp = JsonConvert.SerializeObject(item, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var t = new TerminatePointAdjust(); t = JsonConvert.DeserializeObject <TerminatePointAdjust>(temp); t.ID = 0; this._context.TerminatePointAdjusts.Add(t); } var user = this._context.Users.Where(w => w.ID == customer.UserID).FirstOrDefault(); if (user != null) { var rg = new RijndaelCrypt(); var u = rg.Encrypt(user.UserName); var p = rg.Encrypt(DataEncryptor.Decrypt(user.Password)); var flag = rg.Encrypt(customer.FacebookFlag); var tempuser = JsonConvert.SerializeObject(user, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var tuser = new TerminateUser(); tuser = JsonConvert.DeserializeObject <TerminateUser>(tempuser); tuser.ID = 0; tuser.CustomerID = customer.ID; this._context.TerminateUsers.Add(tuser); this._context.CustomerPoints.RemoveRange(points); this._context.MobilePoints.RemoveRange(mobile); this._context.CustomerClassChanges.RemoveRange(classchages); this._context.PointAdjusts.RemoveRange(adjusts); this._context.Redeems.RemoveRange(redeems); this._context.Customers.Remove(customer); this._context.Users.Remove(user); acccode.Status = StatusType.InActive; this._context.SaveChanges(); /*delete customer imobile*/ using (var client = new HttpClient()) { client.BaseAddress = new Uri(_mobile.Url + "/rewardpoint/customerprofile/delete"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var model = new { u = u, p = p, flag = flag }; StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content); if (response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.OK) { customer.Success = true; this._context.SaveChanges(); } } } } } this._loginServices.Logout(); return(View()); }
public async Task <IActionResult> Login(Login model, bool registed = false) { model.UserName = model.UserName.Trim(); model.Password = model.Password.Trim(); ModelState.Remove(""); if (ModelState.IsValid) { // Login statement here var user = this._context.Users.Include(u => u.UserRole).Where(u => u.UserName == model.UserName).FirstOrDefault(); if (user == null) { /*create customer imobile*/ if (user == null) { await this.Repair(model.UserName, model.Password, null, bcrypt : BCrypt.Net.BCrypt.HashPassword(model.Password)); user = this._context.Users.Include(u2 => u2.UserRole).Where(u2 => u2.UserName == model.UserName).FirstOrDefault(); } } if (user != null) { if (registed) { if (user != null && user.Status == UserStatusType.Active) { this._loginServices.Login(user, model.RememberMe); var customer = this._context.Customers.Where(w => w.UserID == user.ID).FirstOrDefault(); if (customer != null) { customer.FirstLogedIn = true; this._context.SaveChanges(); } return(RedirectToAction("RegisterCompleted", new { Email = model.UserName })); } } else { if (user.Status != UserStatusType.InActive) { if (user.UserRole != null && user.UserRole.RoleName == RoleName.Member) { var customer = this._context.Customers.Where(w => w.UserID == user.ID).FirstOrDefault(); if (customer == null) { ViewData["ErrorMessage"] = "ไม่พบข้อมูลผู้ใช้"; return(View(model)); } if (customer.FirstLogedIn == false && customer.Channel == CustomerChanal.TipInsure) { var rg = new RijndaelCrypt(); return(RedirectToAction("ResetPwd", "Accounts", new { u = rg.Encrypt(customer.User.UserName) })); } if (!string.IsNullOrEmpty(user.Password)) { string desPassword = DataEncryptor.Decrypt(user.Password); if (model.Password == desPassword) { this._loginServices.Login(user, model.RememberMe); GetCustomerClass(customer); customer.FirstLogedIn = true; var conditions = this.GetPointCondition(customer, TransacionTypeID.Login); foreach (var con in conditions) { } this._context.SaveChanges(); return(RedirectToAction("Info", "Customer")); } } if (!string.IsNullOrEmpty(customer.BCryptPwd)) { string paintTextPassword = model.Password; string passworeInDB = customer.BCryptPwd; if (!string.IsNullOrEmpty(paintTextPassword) && !string.IsNullOrEmpty(passworeInDB)) { if (BCrypt.Net.BCrypt.Verify(paintTextPassword, passworeInDB)) { user.Password = DataEncryptor.Encrypt(model.Password); customer.Syned = true; this._context.Users.Update(user); this._loginServices.Login(user, model.RememberMe); GetCustomerClass(customer); customer.FirstLogedIn = true; this._context.SaveChanges(); return(RedirectToAction("Info", "Customer")); } } } } else if (user.UserRole.RoleName == RoleName.Merchant) { string desPassword = DataEncryptor.Decrypt(user.Password); if (model.Password == desPassword) { this._loginServices.Login(user, model.RememberMe); return(RedirectToAction("Index", "MerchantU")); } } else { string desPassword = DataEncryptor.Decrypt(user.Password); if (model.Password == desPassword) { this._loginServices.Login(user, model.RememberMe); return(RedirectToAction("Index", "Admin")); } } } else { ViewData["ErrorMessage"] = "ถูกระงับการเป็นสมาชิก"; return(View(model)); } } } } ViewData["ErrorMessage"] = "รหัสผู้ใช้ หรือ รหัสผ่านไม่ถูกต้อง"; return(View(model)); }
private void EncryptPassword() { if (txtInput.Text.Length == 0) { return; } EncryptionElement element = comboApplicationId.SelectedItem as EncryptionElement; try { if (element != null) { txtOutPut.Text = checkDecrypt.Checked ? RijndaelCrypt.Decrypt(txtInput.Text, element.ApplicationId) : RijndaelCrypt.Encrypt(txtInput.Text, element.ApplicationId); } txtOutPut.BackColor = SystemColors.Control; txtOutPut.ForeColor = SystemColors.WindowText; } catch (Exception ex) { txtOutPut.Text = ex.Message; txtOutPut.BackColor = Color.Red; txtOutPut.ForeColor = Color.White; } }
public static string Encode(string userId, string password) { return(RijndaelCrypt.Encrypt(password, AppIdentifier)); }