如何解决如何使用FluentValidation创建强密码?
我正在使用FluentValidation设计用户注册屏幕。
我想建立一种控制机制,该机制将提供有关以下所有步骤的信息。
我尝试过的代码;
RuleFor(p => p.Password).Matches(@"[A-Z]+").WithMessage("Your password must contain at least one uppercase letter.");
RuleFor(p => p.Password).Matches(@"[a-z]+").WithMessage("Your password must contain at least one lowercase letter.");
RuleFor(p => p.Password).Matches(@"[0-9]+").WithMessage("Your password must contain at least one number.");
RuleFor(x => x.Password).Matches(@"[\!\?\*\.]*$").WithMessage("Your password must contain at least one (!? *.).");
但是我达不到想要的结果。我还查看了FluentValidation文档,但看不到任何有用的示例。
如果您有帮助,我会很高兴。
谢谢。
解决方法
请参考以下示例:
[options]
addons_path = /mnt/extra-addons
logfile = /etc/odoo/odoo-server.log
动作:
public class Login
{
public string Password { get; set; }
}
public class PassWordValidator : AbstractValidator<Login>
{
public PassWordValidator()
{
RuleFor(p => p.Password).NotEmpty().WithMessage("Your password cannot be empty")
.MinimumLength(8).WithMessage("Your password length must be at least 8.")
.MaximumLength(16).WithMessage("Your password length must not exceed 16.")
.Matches(@"[A-Z]+").WithMessage("Your password must contain at least one uppercase letter.")
.Matches(@"[a-z]+").WithMessage("Your password must contain at least one lowercase letter.")
.Matches(@"[0-9]+").WithMessage("Your password must contain at least one number.")
.Matches(@"[\!\?\*\.]+").WithMessage("Your password must contain at least one (!? *.).");
}
}
这是邮递员的测试结果:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。