Regex that validates Active Directory default password complexity

前端 未结 4 1551
误落风尘
误落风尘 2020-12-19 09:25

I have a list of passwords that I need to examine and determine if they meet the default 3 of 4 rule for AD.

Rule is contain 3 of the 4 following requirements: low

4条回答
  •  不知归路
    2020-12-19 10:30

    If you really want one big regex it would be something like this:

    (?=^.{8,255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^.*
    

    Note that it also enforces password length to be between 8 and 255 characters. You can change the "{8,255}" portion in the first section to adjust the length requirements. It is also worth noting that this is working for me in a standard ASP.NET RegularExpressionValidator control.

    Matches: "Passw0rd" "passW@rd" "1B2a345@#$%"

    Non-Matches: "123123123" "Password" "asdf&"

    Source (Matthew Hazzard via RegExLib.com)

提交回复
热议问题