private void HasPasswordChanged(EditUserViewModel updateUserPassword, User usersOriginalPassword) { bool passwordMatch = _passwordManager.IsPasswordMatch(updateUserPassword.CurrentPassword, usersOriginalPassword.Salt, usersOriginalPassword.PasswordHash); if (!string.IsNullOrEmpty(updateUserPassword.CurrentPassword)) { //check to see if matches that in database if (passwordMatch) { //Save new password string salt = string.Empty; usersOriginalPassword.PasswordHash = _passwordManager.GeneratePasswordHash(updateUserPassword.NewPassword, out salt); usersOriginalPassword.Salt = salt; } } }
private User UpdateUserWithNewValues(EditUserViewModel newValues) { User updatedUser = _db.Users.Find(newValues.UserID); HasPasswordChanged(newValues, updatedUser); updatedUser.Username = HasUsernameChanged(newValues.Username, updatedUser.Username); updatedUser.Email = HasEmailChanged(newValues.Email, updatedUser.Email); updatedUser.ProfilePicture = newValues.ProfilePicture; updatedUser.FirstName = newValues.FirstName; updatedUser.LastName = newValues.LastName; updatedUser.IsActive = newValues.IsActive; return updatedUser; }