Asp.net mvc 5 更改消息";密码必须至少有一个非字母或数字字符。”;
我正在使用Asp.Net身份密码验证程序,希望能得到一些帮助来更改此默认消息,使其更加清晰 如何更改此消息并包括特殊字符(例如)Asp.net mvc 5 更改消息";密码必须至少有一个非字母或数字字符。”;,asp.net-mvc-5,asp.net-identity,Asp.net Mvc 5,Asp.net Identity,我正在使用Asp.Net身份密码验证程序,希望能得到一些帮助来更改此默认消息,使其更加清晰 如何更改此消息并包括特殊字符(例如) manager.PasswordValidator = new PasswordValidator { RequiredLength = 10, RequireNonLetterOrDigit = true, RequireDigit = true, Re
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 10,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true
};
为IdentityExtensions创建一个文件夹,在该类中添加一个类CustomPasswordValidator,您需要参考IIIdentityValidator下面是我如何跳过密码验证的 这是一个
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text.RegularExpressions;
使用System.Threading.Tasks;
使用System.Web;
namespace YourNameSpace.IdentityExtensions
{
公共类CustomPasswordValidator:IIdentityValidator
{
public int RequiredLength{get;set;}
公共CustomPasswordValidator(整数长度)
{
所需长度=长度;
}
公共任务ValidateAsync(字符串项)
{
if(String.IsNullOrEmpty(item)| | item.Length
没问题,很高兴我能帮忙
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
namespace YourNameSpace.IdentityExtensions
{
public class CustomPasswordValidator : IIdentityValidator<string>
{
public int RequiredLength { get; set; }
public CustomPasswordValidator(int length)
{
RequiredLength = length;
}
public Task<IdentityResult> ValidateAsync(string item)
{
if (String.IsNullOrEmpty(item) || item.Length < RequiredLength)
{
return Task.FromResult(IdentityResult.Failed(String.Format("Password should be of length {0}", RequiredLength)));
}
string pattern = @"^(?=.*[0-9])(?=.*[!@#$%^&*])[0-9a-zA-Z!@#$%^&*0-9]{10,}$";
if (!Regex.IsMatch(item, pattern))
{
return Task.FromResult(IdentityResult.Failed("Password should have one numeral and one special character"));
}
return Task.FromResult(IdentityResult.Success);
}
}
}