我必须应用密码策略,并且我正在使用此Regex(我的Identity Server的默认设置),该Regex接受以小写,大写,数字和特殊字符组成的密码:
^((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&*])).{0,100}$
我需要对其进行修改,以使其不匹配具有相同字符的三个以上连续副本的字符串,例如Adminnnn@123
。
答案 0 :(得分:1)
这很棘手,但是我认为这应该可行(try it out live here):
^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&*])(?!.*(.)\1\1\1)[0-9a-zA-Z!@#$%&*]{0,100}$
我正在使用4个超前断言和一个否定超前断言。
(?=.*[0-9]) must contain a number
(?=.*[a-z]) must contain a lower case
(?=.*[A-Z]) must contain an upper case
(?=.*[!@#$%&*]) must contain a special character
(?!.*(.)\1\1\1) must not repeat the character in group 1 more than 3 times
[0-9a-zA-Z!@#$%&*] is composed of these characters
{0,100} 0 to 100 symbols allowed