Orchard core cms 修改注册密码验证难度

因为默认的验证过于严格,不适合中国环境。所以按下面的代码修改:

修改

services.Configure<IdentityOptions>(options =>
 {
   options.Password.RequireDigit = false;
   options.Password.RequireLowercase = true;
   options.Password.RequireUppercase = true;
   options.Password.RequireNonAlphanumeric = false;
   options.Password.RequiredUniqueChars = 3;
   options.Password.RequiredLength = 6;
 });

使用外部配置文件

这样做的目的是方便不同环境切换配置文件

  • Startup.cs
public IConfiguration Configuration { get; }

public Startup(IHostingEnvironment env)
{
  var builder = new ConfigurationBuilder()
      .SetBasePath(env.ContentRootPath)
      .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
      .AddEnvironmentVariables();

  Configuration = builder.Build();
}


public void ConfigureServices(IServiceCollection services)
{
    ...
    services.Configure<IdentityOptions>(options =>
    {
    Configuration.GetSection("IdentityOptions").Bind(options);
    });
    ...
});
}
  • appsetting.json
  "IdentityOptions": {
   "Password": {
     "RequireDigit": false,
     "RequireLowercase": true,
     "RequireUppercase": false,
     "RequireNonAlphanumeric": false,
     "RequiredUniqueChars": 3,
     "RequiredLength": 6
   }