Password Validation using MATCH (RegEx)

Hi All -

Does anyone have an example of Clarion MATCH to validate password for:

Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character.

Thanks

I don’t have one using Match, but if you have StringTheory you can see some example code here;
https://www.capesoft.com/docs/StringTheory3/StringTheory.htm#CheckPasswordStrength

Cheers
Bruce

1 Like

I had roughly the same requirements but did it myself with an IF, ELSIF (several), END structure then starting with a length test followed in the ELSIF sections utilising the various string analysis features within Clarion in each section to pick out the rule failures.A good password can drop through or be picked up with an ELSE. If you wanted with this structure each rejection can have a tailored message with GlobalErrors.ThrowMessage().

Hope that helps

1 Like
PasswordBad     PROCEDURE(STRING pwd),STRING 
    CODE
    IF LEN(CLIP(Pwd)) < 8 THEN                RETURN 'Minimum eight characters'.
    IF ~MATCH(Pwd,'[A-Z]',Match:Regular) THEN RETURN 'at least one uppercase letter '.
    IF ~MATCH(Pwd,'[a-z]',Match:Regular) THEN RETURN 'one lowercase letter '.
    IF ~MATCH(Pwd,'[0-9]',Match:Regular) THEN RETURN 'one number '          .
    IF ~MATCH(Pwd,'[^A-Z^a-z^0-9]',Match:Regular) THEN RETURN 'one special character '.

    IF INSTRING(CHR(32),CLIP(Pwd)) THEN  RETURN 'No Spaces'. !Suggested

    RETURN '' !Ok
4 Likes

The Caret should only be in position 1 to indicate a negative set. Also added a space <32> to be excluded so not considered a special characyer

IF ~MATCH(Pwd,'[^A-Za-z0-9<32>]',Match:Regular) THEN RETURN 'one special character '.

2 Likes

Thanks Carl, this is really helpful.