Error when changing password in Admin mode after migrating to asp Identity

Vote:
 

I have migrated an existing Episerver site to ASP.Identity, pretty much following K Khans blogpost. The site is running newest version of Episerver. At first I was struggeling to get Episervers Identity implementation (using UIUserProvider, UIRoleProvider and UISignInManager) to work with Structure map. After explicit adding interfaces and abstract classes to Structure map config, I've got everything to work except validating a users password when creating or updating users in admin mode: 

Unable to cast object of type 'Microsoft.AspNet.Identity.MinimumLengthValidator' to type 'Microsoft.AspNet.Identity.PasswordValidator'.

Stack trace:
at EPiServer.Cms.UI.AspNetIdentity.ApplicationUserProvider`1.get_MinRequiredPasswordLength() at EPiServer.UI.Edit.UserMembership.ValidatePassword() at EPiServer.UI.Edit.UserMembership.SaveMembershipUser(IEnumerable`1& errors)

at EPiServer.UI.Edit.UserMembership.SaveButton_Click(Object sender, EventArgs e)

I guess there is a simple solution to this, but I've already spent way too much time trying to make it work. Any help or suggestions are greatly appreciated.

Thanks in advance,
Tore.

From Structure map config:

x.For<ApplicationUserManager<ApplicationUser>>().Use<ApplicationUserManager<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<ApplicationUserManager<ApplicationUser>>>().Use(co => new ServiceAccessor<ApplicationUserManager<ApplicationUser>>(() => co.GetInstance<ApplicationUserManager<ApplicationUser>>()));
x.For<UIUserProvider>().Use<ApplicationUserProvider<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<UIUserProvider>>().Use(co => new ServiceAccessor<ApplicationUserProvider<ApplicationUser>>(() => co.GetInstance<ApplicationUserProvider<ApplicationUser>>()));

x.For<UIUserManager>().Use<ApplicationUIUserManager<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<UIUserManager>>().Use(co => new ServiceAccessor<ApplicationUIUserManager<ApplicationUser>>(() => co.GetInstance<ApplicationUIUserManager<ApplicationUser>>()));


x.For<UIRoleProvider>().Use<ApplicationRoleProvider<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<UIRoleProvider>>().Use(co => new ServiceAccessor<ApplicationRoleProvider<ApplicationUser>>(() => co.GetInstance<ApplicationRoleProvider<ApplicationUser>>()));
x.For<ApplicationRoleManager<ApplicationUser>>().Use<ApplicationRoleManager<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<ApplicationRoleManager<ApplicationUser>>>().Use(co => new ServiceAccessor<ApplicationRoleManager<ApplicationUser>>(() => co.GetInstance<ApplicationRoleManager<ApplicationUser>>()));
x.For<ApplicationRoleProvider<ApplicationUser>>().Use<ApplicationRoleProvider<ApplicationUser>>().SetLifecycleTo<HybridLifecycle>();
x.For<ServiceAccessor<ApplicationRoleProvider<ApplicationUser>>>().Use(co => new ServiceAccessor<ApplicationRoleProvider<ApplicationUser>>(() => co.GetInstance<ApplicationRoleProvider<ApplicationUser>>()));

x.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
x.For<DbContext>().Use(() => new ApplicationDbContext<ApplicationUser>());
x.For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);
#210509
Edited, Nov 26, 2019 13:07
Vote:
 

Are you using the default ApplicationUserManager, or are you using your custom implementation?

#210518
Nov 26, 2019 15:18
Vote:
 

Hi Quan, and thanks for your reply. I am using the default ApplicationUserManager, but with Episervers UIUserManager "in front".

#210520
Nov 26, 2019 15:30
Vote:
 

For starter I think you just need to add this to your Startup.Configuration, you don't have such long configuration for structuremap

app.AddCmsAspNetIdentity<SiteUser>(new ApplicationOptions());

#210526
Nov 26, 2019 16:59
Vote:
 

Thanks again Quan!

Since I've migrated an existing site with existing users, I've added a custom implementation as suggested by K Khan. The implementation is equal to Episervers default, except the call to

app.CreatePerOwinContext<ApplicationUserManager<TUser>>(new Func<IdentityFactoryOptions<ApplicationUserManager<TUser>>, IOwinContext, ApplicationUserManager<TUser>>(ApplicationUserManager<TUser>.Create));

That is changed to 

app.CreatePerOwinContext<ApplicationUserManager<TUser>>(CreateApplicationUserManager);

CreateApplicationUserManager is setting up a custom SqlPasswordHasher and also the Password validator. This is as per Episervers documentation
The password validator is what causes the error for me, but removing it prevents me from logging in with my old password.

As I can see, this is a straight forward implementation as per documentation and should just work..

#210537
Nov 27, 2019 7:40
Vote:
 

That is very strange indeed. I'd suggest you to contact developer support service for further assistance. When we can take a look a closer look at your site it would be easier to spot the problem

#210538
Nov 27, 2019 7:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.