While i was exploring the Power Apps community i saw an interesting questions posted by a user. It gave me a little idea to write a blog post as well and provide the solution to user as well.

Scenario: You want to create a Password reset application. You have to ensure that the new Password adheres to your global policy for Passwords i.e. it should include some upper case and lower case letters, it should have digit and should have a special characters.


There could be different approaches to this solution but i particularly like the IsMatch function of Power Apps and i am going to solve the problem through it.

So to solve the problem, Lets create a canvas app and add an input field and a button

How to check Password Complexity in Canvas Power Apps

The first thing i need to check is if the Password meets my required length. I will be using the Len function of PowerApps. Simple code. I get the length of my first text field and check if its greater then 4. If its true do nothing if its false i set a variable e with possible error statement.

If(Len(password1.Text)>4,0,Set(e,"Error in length"));

Now the next bits are interesting. I want to check if there is a numeric digit in the password. Now i will use isMatch function

If(IsMatch(password1.Text,"[0-9]" ,Contains),0,Set(e,"must contain a numeric digit"))

To break this down for you, i am using Regular Expression to match and used the Contains parameter here so there if there is even a single match it should return true.

Similarly i have added code for Upper Case, Lower Case and Special Characters

My final code on submit button looks like

Set(e,"");If(password1.Text=password2.Text ,0,Set(e,"Two fields are not same")); If(Len(password1.Text)>4,0,Set(e,"Error in length"));If(IsMatch(password1.Text,"[0-9]" ,Contains),0,Set(e,"must contain a numeric digit"));If(IsMatch(password1.Text, "[a-z]"  ,Contains),0,Set(e,"Must contain  small case letter"));If(IsMatch(password1.Text,"[A-Z]" ,Contains),0,Set(e,"Must contain one uper case letter"));If(IsMatch(password1.Text,"[$&+?@#^*()%!]" ,Contains),0,Set(e,"no special character")); 

The placing of these is important.

  1. So first i am setting the error value to empty before starting a new check
  2. Then i check if two fields are the same
  3. Length of password
  4. Upper case and lower case letter or numeric digit or special characters

The reason i put checking two text fields first is because if anything else is fasle it will overwrite that error so i need to make sure before user get the error of the same fields i should make sure that the password in first field satisfies my requirment.

How to check Password Complexity in Canvas Power Apps

Hope this quick tip will help you make better apps 🙂