Currently I'm seeking for the possibility for hashing a password in an ActionResult
.
To be specific, I want to call my SHA512 method in the public ActionResult Edit(User user)
to hash the password if it got changed.
Here is the code of the Edit
method:
[HttpPost]
public ActionResult Edit(User user)
{
if (ModelState.IsValid)
{
db.Entry(user).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(user);
}
I am actually new to ASP.NET and I really don't know how to call this method in order to hash the new password, if there is one:
public static string SHA512(string value)
{
byte[] result;
SHA512 sha512 = new SHA512Managed();
result = sha512.ComputeHash(Encoding.Default.GetBytes(value));
string hash = BitConverter.ToString(result).Replace("-", String.Empty);
return hash;
}