public async Task <IActionResult> Create([Bind("ProductId,ProductName,ProductPrice,ProductDescription")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("UserId,Username,Status,Password,DisplayName,Salt,Email")] User user) { if (ModelState.IsValid) { ////////////////////////////////////////////////////////////////////////////////////////////////// //StringBuilder Sb = new StringBuilder(); //using (var hash = SHA256.Create()) //{ // Encoding enc = Encoding.UTF8; // Byte[] result = hash.ComputeHash(enc.GetBytes(user.Password)); // foreach (Byte b in result) // Sb.Append(b.ToString("x2")); //} //user.Password = Sb.ToString(); //user.Status = "User"; //////////////////////////////////////////////////////////////////////////////////// byte[] salt = new byte[128 / 8]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(salt); } string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2( password: user.Password, salt: salt, prf: KeyDerivationPrf.HMACSHA1, iterationCount: 10000, numBytesRequested: 256 / 8)); user.Password = hashed; user.Status = "User"; //StringBuilder Sb = new StringBuilder(); //foreach (Byte b in salt) //{ // Sb.Append(b.ToString("x2")); //} //user.Salt = Sb.ToString(); user.Salt = salt; _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Login))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("ProductId,ProductName,ProductPrice,ProductDescription")] Product product) { string status = HttpContext.Session.GetString("sessionStatus"); if (status == "Admin") { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); } return(RedirectToAction("Index", "Home")); }