public bool ChangePassword(User user, string newPassword) { if (MeetsPasswordPolicy(newPassword)) { user.PasswordHash = ComputePasswordHash(newPassword); _dbContext.SaveChanges(); _logger.LogInformation("Changed password of user " + user.Id); return(true); } _logger.LogInformation( string.Format( "Refused to change password of user {0} because the new password " + "did not meet the password policy", user.Id ) ); return(false); }
public async Task <IActionResult> Update(UserDetails userDetails) { if (ModelState.IsValid) { bool success = false; var Emails = _dbContext.Users.Where(p => p.Email == userDetails.Email); var user = _dbContext.Users.Find(HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); if (user != null && (Emails.Count() == 0 || user.Email == userDetails.Email)) { user.Email = userDetails.Email; user.FirstName = userDetails.FirstName; user.LastName = userDetails.LastName; _dbContext.Users.Update(user); await _caClient.RevokeCertificate(user.Id); _dbContext.SaveChanges(); success = true; } // TempData persists the message to the next request after RedirectToAction if (success) { TempData["SuccessMessage"] = "Account information updated successfully."; } else { TempData["ErrorMessage"] = "Updating account information failed."; } return(RedirectToAction(nameof(Index))); } else { return(View()); } }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new IMoviesUserContext( serviceProvider.GetRequiredService <DbContextOptions <IMoviesUserContext> >())) { if (context.Users.Any()) { return; } context.Users.Add(new User { Id = "test", Email = "*****@*****.**", FirstName = "Test", LastName = "User", // PasswordHash = SHA1("test") PasswordHash = "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3" }); context.SaveChanges(); } }