public IActionResult RegisterUser([Bind] UserModel user) { WebDbContext db = HttpContext.RequestServices.GetService(typeof(Web.Utils.WebDbContext)) as WebDbContext; if (ModelState.IsValid) { // Check if email already exists in db if (db.GetLoginUsername(user) > 0) { return(RedirectToAction("RegisterUserExists")); } // Generate new salt and hash password var password = user.Password.ToString(); PasswordHasher pwHasher = new PasswordHasher(); HashResult hashedPassword = pwHasher.HashNewSalt(password, 20, SHA512.Create()); user.Salt = hashedPassword.Salt; user.Password = hashedPassword.Digest; // Register new user db.RegisterUser(user); // Redirect to user area ModelState.Clear(); return(RedirectToAction("UserLogin")); } // Model data invalid return(RedirectToAction("RegisterModelFailed")); }