public int Add(CustomerinfoViewModel newItem) { try { Customer_Info customer = new Customer_Info() { name = newItem.name, dob = newItem.dob, address = newItem.address, phone = newItem.phone, email = newItem.email, active = newItem.active, username = newItem.username, password = PasswordSecurity.Encrypt(newItem.password), user_type_id = newItem.user_type_id }; context.Customer_Info.Add(customer); context.SaveChanges(); return(1); } catch (EntityException ex) { Debug.Write(ex.Message); return(0); } }
public void EncryptTest() { var newPassword = "******"; var encryptedpassword = PasswordSecurity.Encrypt("securityPassword", newPassword, false); Assert.AreNotEqual(newPassword, encryptedpassword); }
public JsonResult RegisterUser([FromBody] ApplicationUsers users) { users.Pass = Guid.NewGuid().ToString(); users.Password = PasswordSecurity.Encrypt(users.Password, users.Pass); var result = _account.RegisterAccount(users); return(new JsonResult("Success")); }
public ActionResult Convert() { string password = Request.Params["password"]; string encryptPw = PasswordSecurity.Encrypt(password); TempData["encrypt"] = encryptPw; return(RedirectToAction("ConvertPassword", TempData["encrypt"])); }
public void DecryptTest_good_enc_and_dec_dont_match() { var newPassword = "******"; var encryptedpassword = PasswordSecurity.Encrypt("securityPassword", newPassword, false); var decryptedPassword = PasswordSecurity.Decrypt("securityPassword", encryptedpassword, false); Assert.AreNotEqual(encryptedpassword, decryptedPassword); }
public void DecryptTest_good() { var newPassword = "******"; var encryptedpassword = PasswordSecurity.Encrypt("securityPassword", newPassword, false); var decryptedPassword = PasswordSecurity.Decrypt("securityPassword", encryptedpassword, false); Assert.AreEqual(newPassword, decryptedPassword); }
public void TestEncryption() { PasswordSecurity.InitializeAes("So long and thanks for all the fish"); var initial = "MeinSuperGutesPasswort"; var encrypted = PasswordSecurity.Encrypt(initial); var decrypted = PasswordSecurity.Decrypt(encrypted); Assert.AreEqual(initial, decrypted); }
public JsonResult CheckValidUser(CustomerinfoViewModel model) { using (var ctx = new InsuranceDbContext()) { var ecrtPassword = PasswordSecurity.Encrypt(model.password); string result = "Fail"; var DataItem = ctx.Customer_Info.Where(x => x.username == model.username && x.password.Equals(ecrtPassword)).SingleOrDefault(); if (DataItem != null) { Session["id"] = DataItem.id.ToString(); Session["username"] = DataItem.username.ToString(); result = "Success"; } return(Json(result, JsonRequestBehavior.AllowGet)); } }
public void EditPassword(int id, string newPassword) { try { using (var db = new connectionsLinqDataContext()) { var encryptedpassword = PasswordSecurity.Encrypt("securityPassword", newPassword, false); db.EditPassword(id, encryptedpassword); } } catch (Exception) { return; } }
public void AddNewUser(UserTable toAddUser) { try { using (connectionsLinqDataContext db = new connectionsLinqDataContext()) { var encryptedpassword = PasswordSecurity.Encrypt("securityPassword", toAddUser.password, false); db.AddNewUser(toAddUser.userId, toAddUser.username, toAddUser.name, toAddUser.email, encryptedpassword, toAddUser.avatar, toAddUser.points, toAddUser.money, toAddUser.gamesPlayed, toAddUser.leagueName, toAddUser.winNum, toAddUser.HighestCashGainInGame, toAddUser.TotalProfit, toAddUser.inActive); //db.UserTables.InsertOnSubmit(toAddUser); // db.SubmitChanges(); } } catch (Exception e) { return; } }
public async Task <IActionResult> PostNewUser(User user) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } if (_context.Users.Any(u => u.Email.Equals(user.Email))) { return(BadRequest("Email already exists")); } user.Password = PasswordSecurity.Encrypt(user.Password); user.Score = 0; _context.Users.Add(user); await _context.SaveChangesAsync(); return(Ok(new UserDTO(user.UserId, user.Name, user.Score))); }
private void SaveAccount(string tracker, string user, string password) { switch (tracker) { case "Fano.in": config.Write("fanologin", user); config.Write("fanopassword", PasswordSecurity.Encrypt(password, main.mySite)); break; case "Kinozal.tv": config.Write("kinozallogin", user); config.Write("kinozalpassword", PasswordSecurity.Encrypt(password, main.mySite)); break; case "Filebase.ws": config.Write("filebaselogin", user); config.Write("filebasepassword", PasswordSecurity.Encrypt(password, main.mySite)); break; } }
public async Task <IActionResult> Update([DataSourceRequest] DataSourceRequest request, WebPluginConstantViewModel viewModel) { var tenantId = viewModel.TenantId; if (!isSysAdmin) { tenantId = db.CurrentTenantId; } var model = db.WebPluginConstants.First(n => n.TenantId == tenantId && n.WebPluginConstantId == viewModel.WebPluginConstantId); if (ModelState.IsValid) { await this.TryUpdateModelAsync <WebPluginConstantViewModel, WebPluginConstant>(model, "", m => { return(m.ElementType == null); }); if (model.Value.StartsWith("encrypt:")) { if (tenantId == null || !options.Value.UseExplicitTenantPasswords) { model.Value = PasswordSecurity.Encrypt(model.Value.Substring(8)); } else { var t = db.Tenants.First(n => n.TenantId == tenantId); if (!string.IsNullOrEmpty(t.TenantPassword)) { var pwd = Convert.FromBase64String(t.TenantPassword); model.Value = AesEncryptor.Encrypt(model.Value.Substring(8), pwd, false); } else { model.Value = PasswordSecurity.Encrypt(model.Value.Substring(8)); } } } model.TenantId = tenantId; await db.SaveChangesAsync(); } return(Json(await new[] { model.ToViewModel <WebPluginConstant, WebPluginConstantViewModel>() }.ToDataSourceResultAsync(request, ModelState))); }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var stringValue = (string)value; if (string.IsNullOrEmpty(stringValue)) { writer.WriteNull(); return; } if (stringValue.StartsWith("encrypt:", StringComparison.OrdinalIgnoreCase)) { stringValue = PasswordSecurity.Encrypt(stringValue.Substring(8)); } writer.WriteValue(stringValue); /*var buffer = Encoding.UTF8.GetBytes(stringValue); * * using (var inputStream = new MemoryStream(buffer, false)) * using (var outputStream = new MemoryStream()) * using (var aes = new AesManaged * { * Key = _encryptionKeyBytes * }) * { * var iv = aes.IV; // first access generates a new IV * outputStream.Write(iv, 0, iv.Length); * outputStream.Flush(); * * var encryptor = aes.CreateEncryptor(_encryptionKeyBytes, iv); * using (var cryptoStream = new CryptoStream(outputStream, encryptor, CryptoStreamMode.Write)) * { * inputStream.CopyTo(cryptoStream); * } * * Convert.ToBase64String(outputStream.ToArray())); * }*/ }
public ActionResult UpdatePassword() { int id = (int)Session["id"]; string oldPassword = Request.Params["oldPassword"]; string newPassword = Request.Params["newPassword"]; string reNewPassword = Request.Params["reNewPassword"]; CustomerinfoDAORequest request = new CustomerinfoDAORequest(); var customer = request.GetCustomerById(id); if (!CheckNullField(oldPassword, newPassword, reNewPassword)) { if (CheckOldPassword(customer.password, oldPassword)) { if (CheckMatchNewPassword(newPassword, reNewPassword)) { customer.password = PasswordSecurity.Encrypt(newPassword); request.Update(customer); return(RedirectToAction("Index")); } else { TempData["Alert"] = "New password not match"; return(RedirectToAction("ChangePassword")); } } else { TempData["Alert"] = "Old Password is not corrent"; return(RedirectToAction("ChangePassword")); } } else { TempData["Alert"] = "Please Enter All Of Field"; return(RedirectToAction("ChangePassword")); } }
public ActionResult LoginDB(CustomerinfoViewModel uv) { using (var ctx = new InsuranceDbContext()) { string pw = uv.password; if (Session["id"] == null) { var ecrtPassword = PasswordSecurity.Encrypt(pw); var checkus = ctx.Customer_Info .Where(a => a.username.Equals(uv.username)) .FirstOrDefault(); if (checkus != null) { var obj = ctx.Customer_Info.Where(a => a.username.Equals(uv.username) && a.password.Equals(ecrtPassword)).FirstOrDefault(); if (obj != null) { var ut = ctx.User_Type.Where(t => t.id == obj.user_type_id).Select(t => t.name).FirstOrDefault().ToString(); var sta = obj.active == true ? "Unlock" : "Lock"; if (sta == "Unlock") { if (ut == "Admin") { Session["id"] = obj.id; Session["username"] = obj.username; Session["User_Type"] = ctx.User_Type.Where(utt => utt.id == obj.id).Select(utt => utt.name).FirstOrDefault(); //TempData["Alert"] = "Welcome admin!"; return(RedirectToAction("DashIndex", "DashBoard")); } else { Session["id"] = obj.id; Session["username"] = obj.username; Session["User_Types"] = ctx.User_Type.Where(utt => utt.id == obj.id).Select(utt => utt.name).FirstOrDefault(); //TempData["Alert"] = "Have a nice day!"; return(RedirectToAction("Index", "Home")); } } else { TempData["Alert"] = "Your account has been locked!"; return(RedirectToAction("Login", "Login")); } } else { TempData["Alert"] = "Your password is wrong!"; return(RedirectToAction("Login", "Login")); } } else { TempData["Alert"] = "Your account not exist!"; return(RedirectToAction("Login", "Login")); } } else { TempData["Alert"] = "Please log out to be able to log in with another account!"; return(RedirectToAction("Index", "Home")); } } }