Validate password rules

who I can check if the Password field should contain at least eight characters, including at least one number, and includes
Letters. If not should throw a business exception “invalid password”

Hi,

If you have the password as string, you can put this expression in IF CONDICTION

System.Text.RegularExpressions.Regex.IsMatch(variable_text,"(?=.{8,}$)(?=.*[0-9])")

Hey

try the following, it will look for minimum eight characters, at least one letter and one number

System.Text.RegularExpressions.Regex.IsMatch(stringVar, "^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$")

Regards,

Hi @Muneer_Alrashdan

I see you have three requirements to check. The password must contain:

  • Atleast 8 characters
  • atleast 1 number
  • includes letters

Lets say your password is of type string called ‘strPassword’:

To check for 8 characters simply:
Trim and check the length.

To Trim:
strPassword.Trim

Check Length:
Insert ‘IF’ activity and nsert the following into the condition:
strPassword.Length < 8

Then: Insert Throw activity
Else: Insert log message with ‘strPassword.Length.ToString’

To check the password contains atleast 1 number
Use a Regex.IsMatch with an IF activity. Insert the following into the condition:
system.text.regularexpressions.regex.IsMatch(strPassword, “\d”)

Then: Insert Log message “Password contains atleast 1 number”
Else: Insert Throw activity

To check the password contains atleast 1 letter
Use a Regex.IsMatch with an IF activity. Insert the following into the condition:
system.text.regularexpressions.regex.IsMatch(strPassword, “[A-Za-z]”)

Then: Insert Log message “Password contains atleast 1 letter”
Else: Insert Throw activity

.

BONUS Requirements

To check the password contains atleast 1 uppercase/capital letter
Use a Regex.IsMatch with an IF activity. Insert the following into the condition:
system.text.regularexpressions.regex.IsMatch(strPassword, “[A-Z]”)

Then: Insert Log message “Password contains atleast 1 capital letter”
Else: Insert Throw activity

To check the password contains atleast 1 lowercase letter
Use a Regex.IsMatch with an IF activity. Insert the following into the condition:
system.text.regularexpressions.regex.IsMatch(strPassword, “[a-z]”)

Then: Insert Log message “Password contains atleast 1 lowercase letter”
Else: Insert Throw activity

You can learn Regex from these two sources:

Hopefully this helps :blush:

Cheers

Steve

2 Likes