.net - Core aspnet identity password validator based on the configuration -
public static identitybuilder addcustompasswordvalidator<tuser>(this identitybuilder builder, passwordvalidateoptions options) tuser : class { if (!options.emailinpassword) builder.addpasswordvalidator<emailinpasswordvalidator>(); if (!options.usernameinpassword) builder.addpasswordvalidator<usernameinpasswordvalidator>(); if (!options.lastpasswordsinpassword) builder.addpasswordvalidator<lastpasswordsinpasswordvalidator>(); return builder ; }
in above method, can not pass arguments via prop or constructor ipasswordvalidator implementation.
for instance lastpasswordvalidator, want configure based on no. of password counts options, addpasswordvalidator doesn't take data.
public class lastpasswordsinpasswordvalidator:ipasswordvalidator<applicationuser> { private int lastpasswordscount { get; set; } public lastpasswordsinpasswordvalidator(ipasswordhasher<applicationuser> passwordhasher) { this.passwordhasher = passwordhasher; } }
this
builder.addpasswordvalidator<lastpasswordsinpasswordvalidator>(options);
but addpasswordvalidator has no overload.!!!
startup configure services.
ioptions pattern made life easier, ++core design pattern no need pass data via properties/constructor when need data across application, ioptions hold you
services.configure<passwordvalidateoptions>(configuration.getsection("passwordvalidateoptions"));
implementation of ipasswordvalidator
private passwordvalidateoptions passwordvalidateoptions { get; set; } public lastpasswordsinpasswordvalidator(ioptions<passwordvalidateoptions> options) { this.passwordvalidateoptions = options.value; }
Comments
Post a Comment