diff --git a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs index c3da14da23..9188f5328f 100644 --- a/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/MemberRepository.cs @@ -323,7 +323,7 @@ namespace Umbraco.Core.Persistence.Repositories { changedCols.Add("LoginName"); } - // DO NOT update the password if it is null or empty + // DO NOT update the password if it has not changed or if it is null or empty if (dirtyEntity.IsPropertyDirty("RawPasswordValue") && entity.RawPasswordValue.IsNullOrWhiteSpace() == false) { changedCols.Add("Password"); diff --git a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs index 8fac8d8c11..fb6ed8ef39 100644 --- a/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/UserRepository.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models.Membership; @@ -170,8 +171,42 @@ namespace Umbraco.Core.Persistence.Repositories var userFactory = new UserFactory(entity.UserType); var userDto = userFactory.BuildDto(entity); - Database.Update(userDto); + var dirtyEntity = (ICanBeDirty)entity; + //build list of columns to check for saving - we don't want to save the password if it hasn't changed! + //List the columns to save, NOTE: would be nice to not have hard coded strings here but no real good way around that + var colsToSave = new Dictionary() + { + {"userDisabled", "IsApproved"}, + {"userNoConsole", "IsLockedOut"}, + {"userType", "UserType"}, + {"startStructureID", "StartContentId"}, + {"startMediaID", "StartMediaId"}, + {"userName", "Name"}, + {"userLogin", "Username"}, + {"userEmail", "Email"}, + {"userLanguage", "Language"}, + {"defaultToLiveEditing", "DefaultToLiveEditing"} + }; + + //create list of properties that have changed + var changedCols = colsToSave + .Where(col => dirtyEntity.IsPropertyDirty(col.Value)) + .Select(col => col.Key) + .ToList(); + + // DO NOT update the password if it has not changed or if it is null or empty + if (dirtyEntity.IsPropertyDirty("RawPasswordValue") && entity.RawPasswordValue.IsNullOrWhiteSpace() == false) + { + changedCols.Add("userPassword"); + } + + //only update the changed cols + if (changedCols.Count > 0) + { + Database.Update(userDto, changedCols); + } + //update the sections if they've changed var user = (User)entity; if (user.IsPropertyDirty("AllowedSections")) diff --git a/src/Umbraco.Core/TypeExtensions.cs b/src/Umbraco.Core/TypeExtensions.cs index d61ad60144..98d5125f44 100644 --- a/src/Umbraco.Core/TypeExtensions.cs +++ b/src/Umbraco.Core/TypeExtensions.cs @@ -113,11 +113,12 @@ namespace Umbraco.Core } - /// - /// Determines whether the specified type is enumerable. - /// - /// The type. - internal static bool HasParameters(this MethodInfo method, params Type[] parameterTypes) + /// + /// Determines whether the specified type is enumerable. + /// + /// The type. + /// + internal static bool HasParameters(this MethodInfo method, params Type[] parameterTypes) { var methodParameters = method.GetParameters().Select(parameter => parameter.ParameterType).ToArray();