Regex that validates Active Directory default password complexity

前端 未结 4 1550
误落风尘
误落风尘 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:25

    You will have to build up the regular expression like this:

    rule = [ "[a-z]", "[A-Z]", "[0-9]", "[!@#$%\^\&\(\)\+=]" ]
    
    regex = ""
    first = true
    for a in 0..3:
      for b in 0..3:
        if a == b: continue
        for c in 0..3:
          if a == c or b == c: continue
          if not first:
            regex += "|"
          regex += "(" + rule[a] + ".*" + rule[b] + ".*" + rule[c] + ")"
          first = false
    

    I'm not sure if I escaped the special characters correctly. It's kind of dependant on the language/toolkit you're using.

提交回复
热议问题