首页 > 解决方案 > 使用 ASP.Net Web 应用程序的 DataAnnotation 强制执行身份密码规则

问题描述

我有一个带有 EntityFrameWorkStore 托管标识的 web 应用程序。我已经设置了这样的密码要求:

 services.AddIdentity<User, IdentityRole>(o =>
          {
              o.Password.RequireDigit = true;
              o.Password.RequiredLength = 8;
              o.Password.RequireLowercase = true;
              o.Password.RequireNonAlphanumeric = false;
              o.Password.RequireUppercase = true;
          })

有没有办法让 DataAnnotations 强制执行 Requations?我目前正在使用这样的正则表达式:

    [Required]
    [RegularExpression(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$")]
    [DataType(DataType.Password)]
    public string NewPassword { get; set; }

先感谢您

标签: c#asp.netdata-annotations

解决方案


推荐阅读