KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use Match Regex to verify password complexity
PRODUCT: 4D | VERSION: 13.1 | PLATFORM: Mac & Win
Published On: September 20, 2012

The following utility method can be used to test password complexity. To accomplish this it uses regular expressions and the Match Regex command. It accepts a text object and returns a boolean. True if the password meets all the rules defined by the regular expresion and false if it fails to meet all the rules.

C_TEXT($pattern;$test;$1)
C_BOOLEAN($0)

$test:=$1

$pattern:="(?=^.{8,}$)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\d)(?=.*?\W)"

$0:=Match regex($pattern;$test;1)


For a password to be considered complex enough by this set of rules it must contain one or more of the following. A lowercase letter, an uppercase letter, a number, and a special character, ie. #$!@% etc. It also must contain at least eight characters.

The regex can be broken down into pieces with each pieces checking one part of the rules. This makes it easy to change the password requirements to make the utility method more or less restrictive.

(?=^.{8,}$): Checks for eight or more characters
(?=.*?[a-z]): Checks for a lowercase letter
(?=.*?[A-Z]): Checks for an uppercase letter
(?=.*?\d): Checks for a number
(?=.*?\W): Checks for a special character

Below are a few examples of passwords that failed to meet the rules and one example that did.

C_TEXT($password)
C_BOOLEAN($pass)

$password:="simple"
$pass:=checkPass ($password)
//$pass = false

$password:="simplelonger"
$pass:=checkPass ($password)
//$pass = false

$password:="comPlex"
$pass:=checkPass ($password)
//$pass = false

$password:="comPlex*er"
$pass:=checkPass ($password)
//$pass = false

$password:="comPl3xer"
$pass:=checkPass ($password)
//$pass = false

$password:="comP!3xer"
$pass:=checkPass ($password)
//$pass = true